1         BsTable bsTable = new BsTable();
 2 
 3 //        String time = request.getParameter("date");
 4         String time = Constant.getStringDate(0);
 5         
 6         Map<String, String> map = new HashMap<String, String>();
 7         map.put("attendanceDate", time);
 8         
 9         params.clear();
10         params.putAll(map);
11         
12         StringBuilder strSQL = new StringBuilder("SELECT apply_user_name 'name', ");
13         strSQL.append(" count(CASE WHEN type='1' THEN type END) 'field1', ");                //迟到
14         strSQL.append(" count(CASE WHEN type='3' THEN type END) 'field3', ");                //未签到
15         strSQL.append(" count(CASE WHEN type='4' THEN type END) 'field4', ");                //请假
16         strSQL.append(" count(CASE WHEN type='5' THEN type END) 'field5', ");                //外出
17         strSQL.append(" count(CASE WHEN leave_type='病假' THEN leave_type END) 'field10',");    //病假
18         strSQL.append(" count(CASE WHEN leave_type='事假' THEN type END) 'field11' ");        //事假
19         strSQL.append(" FROM t_sign_record_late ");
20         strSQL.append(" WHERE attendance_date=:attendanceDate");
21         strSQL.append(" GROUP BY apply_user_name ");
22 
23         List report_list = signRecordReportDao.findBySql(strSQL.toString(), params);
24         
25         String strSQL_count = "SELECT COUNT(*) FROM (" + strSQL.toString() + ") t";
26         bsTable.setTotal(signRecordReportDao.countBySql(strSQL_count).longValue());
27         bsTable.setRows(report_list);
28         
29     
30         return bsTable;

SpringMVC + Hibernate,使用事务管理 Service 层。但是这段代码放在 controller 里面就会遇到错误!

解决方法就是把数据库的相关操作放在 Service 层,用事务来管理就不会出错了

posted on 2017-08-22 09:36  jarod99  阅读(284)  评论(0编辑  收藏  举报