按时间检索中,开始时间为00:00:00,结束时间为23:59:59

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



猜你喜欢

转载自blog.csdn.net/HGJacky/article/details/77671647