Mybatis时间范围查询,亲测有效

mysql

1.传入时间范围参数类型是字符串

 <if test="startTime!=null and startTime.trim() neq ''">
    and date_format(create_time,'%Y-%m-%d %H:%i:%s') &gt;= str_to_date(#{startTime},'%Y-%m-%d %H:%i:%s')
  </if>
  <if test="endTime!=null and endTime.trim() neq ''">
    and date_format(create_time,'%Y-%m-%d %H:%i:%s') &lt;= str_to_date(#{endTime},'%Y-%m-%d %H:%i:%s')
  </if>

2.传入时间范围参数类型是Date

 <if test="startTime!=null and startTime.trim() neq ''">
    and date_format(create_time,'%Y-%m-%d %H:%i:%s') &gt;= date_format(#{startTime},'%Y-%m-%d %H:%i:%s')
  </if>
  <if test="endTime!=null and endTime.trim() neq ''">
    and date_format(create_time,'%Y-%m-%d %H:%i:%s') &lt;= date_format(#{endTime},'%Y-%m-%d %H:%i:%s')
  </if>

猜你喜欢

转载自www.cnblogs.com/fly4j/p/12696234.html