zoukankan      html  css  js  c++  java
  • 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
    " +
     3                 "from process_his a inner join `user` b on a.creUid=b.id
    " +
     4                 "     inner join t_produce_task_detail c on a.taskDetailId=c.id
    " +
     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
    " +
    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     }
  • 相关阅读:
    字符串
    完全背包
    背包2
    0-1背包
    生日劲歌会
    设计照明系统
    宝岛探险
    汉诺塔问题
    并查集 黑帮危机
    数塔问题
  • 原文地址:https://www.cnblogs.com/jonney-wang/p/7156627.html
Copyright © 2011-2022 走看看