mapper.xml如何处理foreach中的多条件逻辑

y1aodyip  于 2021-06-30  发布在  Java
关注(0)|答案(0)|浏览(249)

我要动手术。我需要比较数据库中的开始时间和结束时间。现在我需要写一个循环来判断日期列表。这是现有单一日期验证的逻辑。我应该如何写foreach来判断日期表

SELECT t_rese_.* 
FROM reserve t_rese_
WHERE 1=1
<if test="entity.meetingRoomId != null and entity.meetingRoomId != ''">
AND t_rese_.meeting_room_id = #{entity.meetingRoomId}
</if>
AND (t_rese_.free_time is NULL or t_rese_.free_time = '1971-01-01 00:00:00')
AND t_rese_.is_delete = 0
<if test="entity.startDate != null and entity.endDate != null">
AND
((CONCAT(t_rese_.start_date,' ',t_rese_.start_time) &gt;= DATE_FORMAT(#{entity.startDate}, '%Y-%m-%d %H:%i:%s')
AND
CONCAT(t_rese_.start_date,' ',t_rese_.start_time) &lt; DATE_FORMAT(#{entity.endDate}, '%Y-%m-%d %H:%i:%s') )
OR
(CONCAT(t_rese_.end_date,' ',t_rese_.end_time) &gt; DATE_FORMAT(#{entity.startDate}, '%Y-%m-%d %H:%i:%s')
AND
CONCAT(t_rese_.end_date,' ',t_rese_.end_time) &lt;= DATE_FORMAT(#{entity.endDate}, '%Y-%m-%d %H:%i:%s') )
OR
(CONCAT(t_rese_.start_date,' ',t_rese_.start_time) &lt;= DATE_FORMAT(#{entity.startDate}, '%Y-%m-%d %H:%i:%s')
AND
CONCAT(t_rese_.end_date,' ',t_rese_.end_time) &gt;= DATE_FORMAT(#{entity.endDate}, '%Y-%m-%d %H:%i:%s') )
OR
(CONCAT(t_rese_.start_date,' ',t_rese_.start_time) &gt;= DATE_FORMAT(#{entity.startDate}, '%Y-%m-%d %H:%i:%s')
AND
CONCAT(t_rese_.end_date,' ',t_rese_.end_time) &lt;= DATE_FORMAT(#{entity.endDate}, '%Y-%m-%d %H:%i:%s') ))
</if>
ORDER BY CONCAT(t_rese_.start_date,' ',t_rese_.start_time) ASC

暂无答案!

目前还没有任何答案,快来回答吧!

相关问题