1.xml标签用法
1.1<where> <if> ,<foreach>
<select id="listByRangeCode" resultType="io.supers.system.entity.SysRoleEntity">
select DISTINCT sr.role_id, sr.*
FROM sys_role sr
LEFT JOIN sys_user_role sur on sur.role_id = sr.role_id
<where>
<if test="userId != null and userId != ''">
and (sr.create_user_id = #{userId}
OR sur.user_id = #{userId})
</if>
<if test="rangeCode != null and rangeCode != ''">
and
<foreach item="item" collection="rangeCode" open="(" separator=" or " close=")">
FIND_IN_SET(#{item}, sr.range_code)
</foreach>
</if>
</where>
</select>
select DISTINCT sr.role_id, sr.* FROM sys_role sr LEFT JOIN sys_user_role sur on sur.role_id = sr.role_id WHERE ( FIND_IN_SET(?, sr.range_code) or FIND_IN_SET(?, sr.range_code) )