mapper.xml
1、IN 方法, 字符串集合参数处理方式 in(’?’ ,’?’ ,’?’)
入参数 timeList —> List 集合 -->
参数为:
索引0= ‘2020-06-09’
索引1= ‘2020-06-10’
where day_time in
<foreach collection="timeList" item="item" index="index" open="(" close=")" separator=",">
#{item, jdbcType=VARCHAR}
</foreach>
处理后sql为 :
WHERE day_time in ( '2020-06-09' , '2020-06-10' )
2、逗号分隔的字符串参数处理方法 and(a=’?’ or a=’?’ or a=’?)
入参:facilities=" 1,2,3" —> CONCAT(CONCAT('%','1'), '%')
是为了处理模糊查询
<if test="facilities != null">
<foreach item="item" index="index" collection="facilities.split(',')" open="and(1 != 1 " separator=""
close=")">
or hr.facilities like CONCAT(CONCAT('%',#{item}), '%')
or h.facilities like CONCAT(CONCAT('%',#{item}), '%')
</foreach>
</if>
处理后sql为 :
and(
1 != 1
or h.facilities like CONCAT(CONCAT('%','1'), '%')
or h.facilities like CONCAT(CONCAT('%','2'), '%')
or h.facilities like CONCAT(CONCAT('%','3'), '%')
)
3、特殊符号处理
在mapper 中某些符号是不可用的,如: >, <
<![CDATA[
and hr.guard_num >= #{guardNum}
]]>
4、模糊查询处理
在mapper 中是不是直接输入 % 号的,需要CONCAT方法处理
h.city like CONCAT(CONCAT('%',#{search}), '%')