mybatis中模糊查询like拼接问题
<!-- ******************** 模糊查询的常⽤的3种⽅式:********************* -->父亲的菜园
<lect id="getUrsByFuzzyQuery" parameterType="Ur" resultType="Ur">
lect <include refid="columns"/> from urs
<where>
<!--
⽅法⼀: 直接使⽤ % 拼接字符串
昆明金马碧鸡坊注意:此处不能写成 "%#{name}%" ,#{name}就成了字符串的⼀部分,
会发⽣这样⼀个异常: The error occurred while tting parameters,
应该写成: "%"#{name}"%",即#{name}是⼀个整体,前后加上%
-->
<if test="name != null">
黄山四绝name like "%"#{name}"%"
实在的近义词
</if>
<!--⽅法⼆: 使⽤concat(str1,str2)函数将两个参数连接 -->
<if test="phone != null">
and phone like concat(concat("%",#{phone}),"%")
</if>
<!--⽅法三: 使⽤ bind 标签,对字符串进⾏绑定,然后对绑定后的字符串使⽤ like 关键字进⾏模糊查询 -->
<if test="email != null">
心理学的书推荐<bind name="pattern" value="'%'+email+'%'"/>
and email like #{pattern}
穿越星空
</if>
</where>
</lect>
4. 表达式:name like '%'||#{name}||'%'
烤猪
这个不能满⾜要求,直接把数据库中的所有数据查询出来了,不符合我的要求,在mysql中||代表是or的意思
可爱微信名==> Preparing: lect count(0) from (lect *from bbs_brand WHERE name like'%'||?||'%' and falg=?) as total ==>Parameters: 莲(String), 1(Integer)
亲测mysql数据库 使⽤Concat函数没有问题,另外两种⽅法均出现查所有问题。