Java 如何使用单个url映射检索数据并将其插入数据库
我正在使用SpringREST和hibernate,我希望在单个url映射上检索数据并将其更新到数据库中。我正在检索一列数据,在对该数据求和后,我想将该数据更新到另一个表中,但无法更新 这是我的道课Java 如何使用单个url映射检索数据并将其插入数据库,java,mysql,spring,hibernate,rest,Java,Mysql,Spring,Hibernate,Rest,我正在使用SpringREST和hibernate,我希望在单个url映射上检索数据并将其更新到数据库中。我正在检索一列数据,在对该数据求和后,我想将该数据更新到另一个表中,但无法更新 这是我的道课 public List<Post> getPostList() throws Exception { session = sessionFactory.openSession(); Criteria cr = session.createCriteria(Post.cla
public List<Post> getPostList() throws Exception {
session = sessionFactory.openSession();
Criteria cr = session.createCriteria(Post.class);
ProjectionList projList = Projections.projectionList();
projList.add(Projections.sum("val"));
projList.add(Projections.groupProperty("userId"));
cr.setProjection(projList);
List postList = cr.list();
tx = session.getTransaction();
session.beginTransaction();
tx.commit();
return postList;
}
这是我的休息控制器
@RequestMapping(value = "/posts", method = RequestMethod.GET)
public @ResponseBody
List<Post> getEmployee() {
List<Post> postList = null;
try {
postList = profileService.getPostList();
} catch (Exception e) {
e.printStackTrace();
}
return postList;
}
@RequestMapping(value=“/posts”,method=RequestMethod.GET)
公共@ResponseBody
列表getEmployee(){
List postList=null;
试一试{
postList=profileService.getPostList();
}捕获(例外e){
e、 printStackTrace();
}
返回postList;
}
我想检索和更新数据使用单一的网址..请建议我
@RequestMapping(value = "/posts", method = RequestMethod.GET)
public @ResponseBody
List<Post> getEmployee() {
List<Post> postList = null;
try {
postList = profileService.getPostList();
} catch (Exception e) {
e.printStackTrace();
}
return postList;
}