【发布时间】:2017-12-12 16:30:41
【问题描述】:
我是 Hibernate 的新手,正在尝试创建一个返回当前位置的 API。 所以在 DaoImpl 我写了一个查询
public List<Location> getCurrentLocation() {
return sessionFactory.getCurrentSession().createQuery("select l.employee.id, max(l.locationTime) as currentTime, l.longtitude , l.latitude,l.date from Location l group by l.employee.id").list();
}
在控制器中
@RequestMapping(value = "currentLocation", method = RequestMethod.GET)
public ResponseEntity<List<Location>> getCurrentLocation() {
List<Location> location;
try {
location = locationService.getCurrentLocation();
} catch (Exception e) {
System.out.println(e.getMessage());
return new ResponseEntity<List<Location>>(HttpStatus.NO_CONTENT);
}
return new ResponseEntity<List<Location>>(location, HttpStatus.OK);
}
当我调用该 API 时,我会收到此响应
[[11,"07:30:00",106.634756,10.826307,"2017-11-23"],[15,"07:00:00",106.632142,10.826456,"2017-11-24"]]
我只想问为什么我不能得到属性名。我还是不明白。
有没有人可以解释一下,我怎样才能得到属性名称
例如['employeename':11,'time':"07:30:00",'longtitude':106.634756,'latitude':10.826307,'workday':"2017-11-23"]
请帮帮我
【问题讨论】:
标签: hibernate rest api spring-boot