1.时间范围的查询
<select id="list" resultType="SceneDailyMaintainContent">
select <include refid="Base_Column_List" />
from scene_daily_maintain_content t
<where>
<if test="startTimeStart != null and startTimeEnd != null">
and date_format(#{startTimeStart}, '%Y-%m-%d') <![CDATA[<=]]> START_TIME AND START_TIME <![CDATA[<=]]> date_format(#{startTimeEnd}, '%Y-%m-%d')
</if>
<if test="endTimeStart != null and endTimeEnd!=null ">
and date_format(#{endTimeStart}, '%Y-%m-%d')<![CDATA[<=]]>END_TIME and END_TIME <![CDATA[<=]]> date_format(#{endTimeEnd}, '%Y-%m-%d')
</if>
<!-- 添加数据权限 -->
<include refid="Basic.dataAuthSql"></include>
</where>
order by create_time desc
</select>
实体类添加字段
/**
* 时间范围
*/
@TableField(exist = false)
private Date startTimeStart;
@TableField(exist = false)
private Date startTimeEnd;
@TableField(exist = false)
private Date endTimeStart;
@TableField(exist = false)
private Date endTimeEnd;
2.遍历集合foreach循环的使用
<select id="getAmpnInfoByDateAndClassIds" resultType="EduAmPmCheckDetail">
select t.*, c.id classId, c.name className
from edu_am_pm_check_detail t
left join edu_class c on c.id = t.class_id and c.del_flag = '0'
<where>
t.del_flag = '0'
and t.check_date = #{setDate}
<if test="eduClassList != null and eduClassList.size()>0">
and t.class_id in
<foreach collection="eduClassList" index="index" item="eduClass" open="(" separator="," close=")">
#{eduClass.id}
</foreach>
</if>
</where>
order by c.grade asc, c.class_no asc, t.am_or_pm asc
</select>
List<EduAmPmCheckDetail> getAmpnInfoByDateAndClassIds(@Param("setDate") Date setDate, @Param("eduClassList") List<EduClass> eduClassList);
总结foreach的判断条件一般都需要添加size大小判断和为空判断
添加size大小判断,是因为会出现空集合的情况 如: eduClassList:[]
没定义是为null 定义了没赋值是没有数据的对象,不是null
3.获取当前时间爱你
SELECT * FROM scene_manage_operate_process WHERE `STATUS`='1' AND `IS_TEMP`='0' AND DATE_FORMAT(NOW(), '%Y-%m-%d') = DATE_FORMAT(`LAUNCH_TIME`, '%Y-%m-%d')