1. 程式人生 > >動態獲取當前時間,查詢數據。

動態獲取當前時間,查詢數據。

spa ise 表名 new hist ring class ice result

 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>    

動態獲取當前時間,查詢數據。