按時間檢索中,開始時間為00:00:00,結束時間為23:59:59
阿新 • • 發佈:2019-02-08
開發中遇到問題,按時間檢索,傳值為年月日,到sql就會預設為時間00:00:00,在java中可以通過字串拼接的方式實現。
publicstatic Date getStartTimeOfDate(DatecurrentDate) {
Assert.notNull(currentDate);
String strDateTime =date2String(currentDate,"yyyy-MM-dd") +"00:00:00";
returnstring2Date(strDateTime,"yyyy-MM-dd hh:mm:ss");
}
publicstatic Date getEndTimeOfDate(DatecurrentDate) { Assert.notNull(currentDate); String strDateTime =date2String(currentDate,"yyyy-MM-dd") +"23:59:59"; returnstring2Date(strDateTime,"yyyy-MM-dd hh:mm:ss"); }
也可以在mybatis中拼接字串
<if test="START_TIME != null and START_TIME != ''">
and a.CREATE_DATE <![CDATA[>=]]> CONCAT(#{START_TIME},'00:00:00')
</if>
<if test="END_TIME != null and END_TIME != ''">
and a.CREATE_DATE <![CDATA[<=]]> CONCAT(#{END_TIME},'23:59:59')
</if>