<select id="batchValidateDate" resultType="com.mydo.course.svc.entity.vo.CourseSettingInfoCheckVo">
SELECT keyId, clashCount
from (
<foreach collection="list" item="item" index="index" separator="union all">
SELECT #{item.keyId} as keyId, count(1) as clashCount
FROM table1 t0, table2 t1
WHERE t0.is_del= 0 and t0.id = t1.build_id
and t0.week_day = #{item.weekDay}
AND t1.classroom_id in
<foreach collection="item.classroomIdList" item="classroomId" open="(" separator="," close=")">
#{classroomId}
</foreach>
AND
((DATE_FORMAT( t0.start_time, '%H:%i' ) >= #{item.startTime} AND DATE_FORMAT( t0.start_time, '%H:%i' ) <= #{item.endTime}) OR
(DATE_FORMAT( t0.start_time, '%H:%i' ) <= #{item.startTime} AND DATE_FORMAT( t0.end_time, '%H:%i' ) >= #{item.endTime}) OR
(DATE_FORMAT( t0.end_time, '%H:%i' ) >= #{item.startTime} AND DATE_FORMAT( t0.end_time, '%H:%i' ) <= #{item.endTime}))
<if test="item.keyId !=null and item.keyId !=''">
and t0.key_id not in (#{item.keyId})
</if>
<if test="item.pullId != null and item.pullId !=''">
and t0.pull_id = #{item.pullId}
</if>
</foreach>
) t
where keyId is not null
</select>
通过foreach 拼接union all来实现批量查询,在实现过程中出现异常
org.apache.shardingsphere.sql.parser.sql.segment.dml.expr.simple.ParameterMarkerExpressionSegment cannot be cast to org.apache.shardingsphere.sql.parser.sql.segment.LiteralExpressionSegment
经过仔细排查,发现是由于上面sql中标红的地方不能采用#{}这个方法来显示列,而应该使用${}这种方式,困扰了半天,特此记录。