hibernate 返回自定义对象

关键代码老是忘记 setResultTransformer(Transformers.aliasToBean(LabourResult.class)) 

代码用例:

 1     public List<LabourResult> getLabourResult(String startTime, String endTime, Long uid) {
 2         String sql = "select b.name userNo, c.`no` taskDetailNo, sum(a.num) qty, sum(a.ngNum) ngQty\n" +
 3                 "from process_his a inner join `user` b on a.creUid=b.id\n" +
 4                 "     inner join t_produce_task_detail c on a.taskDetailId=c.id\n" +
 5                 "where 1=1 and a.creTime>='" + startTime + "' and a.creTime<='" + endTime + "' ";
 6         if (uid != null) {
 7             sql += " and a.creUid=" + uid;
 8         }
 9         sql += " group by a.creUid, a.taskDetailId\n" +
10                 "order by a.creUid, a.taskDetailId";
11         List labours = processHisDao.getSession().createSQLQuery(sql)
12                 .addScalar("userNo", StandardBasicTypes.STRING)
13                 .addScalar("taskDetailNo", StandardBasicTypes.STRING)
14                 .addScalar("qty", StandardBasicTypes.LONG)
15                 .addScalar("ngQty", StandardBasicTypes.LONG)
16                 .setResultTransformer(Transformers.aliasToBean(LabourResult.class)).list();
17         return labours;
18     }

 

posted on 2017-07-12 17:29  jonney_wang  阅读(1837)  评论(0编辑  收藏  举报

导航