mybatis xml常用写法-使用like关键字【整理+转载】

mybatis xml常用写法-使用like关键字【整理+转载】

需求:xml中需要在where中拼接like语句

方法1:concat

1
2
3
4
5
6
7
8
9
10
<where>
<trim suffixOverrides="," >
<if test="id != null and id != ''" >
and id = #{id}
</if>
<if test="name != null and name != ''" >
and name like concat('%',#{name},'%')
</if>
</trim>
</where>

方法2:${}

1
2
3
<if test="examTypeName!=null and examTypeName!=''">
and exam_type_name like '%${examTypeName}%'
</if>

方法3:#{}

1
2
3
<if test="examTypeName!=null and examTypeName!=''">
and exam_type_name like "%"#{examTypeName}"%"
</if>

参考文章