查询条件为时间段sql怎么写
跟前端沟通好,接受两个字段(比较方便不用做分割处理)
//时间段查询
/** 时间段上限 */
@JsonFormat(pattern = "yyyy-MM-dd")
private Date startTime;
/** 时间段下限 */
@JsonFormat(pattern = "yyyy-MM-dd")
private Date endTime;
1、此方式既能接受时间段也能接收时间节点(就是只接收开始日期或者结束日期)
如果只接受开始日期,查询的信息则是(startTime-现在)
如果只接受结束日期,查询的信息则是(endTime之前)
<if test="startTime != null and startTime != ''"><!-- 开始时间检索 -->
and date_format(hard_storage_in.in_storage_time,'%y%m%d') >= date_format(#{
startTime},'%y%m%d')
</if>
<if test="endTime != null and endTime != ''"><!-- 结束时间检索 -->
and date_format(hard_storage_in.in_storage_time,'%y%m%d') <= date_format(#{
endTime},'%y%m%d')
</if>
2、between and 包含边界
<if test="inStorageTime != null and inStorageTime != ''">
hard_storage_in.in_storage_time between #{
startTime} and #{
endTime}
</if>