开发中遇到问题,按时间检索,传值为年月日,到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>