标签:查询 mat ret res 获取 ring java led where
1 HashMap<String,Object> paramMap =new HashMap<String,Object>(); 2 //获取当前时间 3 SimpleDateFormat timesystem = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); 4 Date date = new Date(); 5 6 String createDate = timesystem.format(date); 7 paramMap.put("createDate", createDate); 8 9 //获取当前月,确定表名 10 SimpleDateFormat getmonth = new SimpleDateFormat("M"); 11 String month = getmonth.format(date); 12 paramMap.put("month", month); 13 14 //将当前时间减上一天,做条件查询 15 Calendar calendar =Calendar.getInstance(); 16 calendar.setTime(date); 17 calendar.set(Calendar.DATE, calendar.get(Calendar.DATE)-1); 18 date= calendar.getTime(); 19 String beforetime = timesystem.format(date); 20 paramMap.put("beforetime", beforetime); 21 return this.thirdAPIService.listdhHistoryRoom(paramMap); 22 }
数据库SQL语句
1 <select id="selectDhRoomHistory" parameterType="java.util.HashMap" resultType="java.util.LinkedHashMap"> 2 <![CDATA[ 3 select * from dh_room_history_${month} 4 ]]> 5 <where> 6 <if test ="beforetime != null"> 7 <![CDATA[ and createDate >= #{beforetime} ]]> 8 </if> 9 <if test ="createDate != null"> 10 <![CDATA[ and createDate <= #{createDate} ]]> 11 </if> 12 </where> 13 </select>
标签:查询 mat ret res 获取 ring java led where
原文地址:https://www.cnblogs.com/fenghh/p/9724085.html