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     }

 


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM