mybatis常用sql场景
# 模糊查询
//mapper: List<Dept> likePids(@Param("deptId") Long deptId);
<select id="likePids" resultType="cn.stylefeng.guns.sys.modular.system.entity.Dept">
select
<include refid="Base_Column_List"/>
from sys_dept where 1 = 1
<if test="deptId != null and deptId != ''">
and pids LIKE CONCAT('%$[',#{deptId},'$]%') escape '$'
</if>
</select>
1
2
3
4
5
6
7
8
9
10
2
3
4
5
6
7
8
9
10
指定参数类型,可以提高查询速度
${_parameter} 和 #{_parameter} 是两种取值方式:"$" 是保持原生态,给什么就拼接什么 。"#"是给你加'',一般用
#{}
escape: 定义转义字符,
“%”、“_”和“[]”
单独出现时,会被认为是通配符对于mysql 的 like 而言,一般都要用 like concat() 组合,可以防止sql注入