mybatis中模糊查询like拼接问题

更新时间:2023-06-19 11:03:40 阅读: 评论:0

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函数没有问题,另外两种⽅法均出现查所有问题。

本文发布于:2023-06-19 11:03:40,感谢您对本站的认可!

本文链接:https://www.wtabcd.cn/fanwen/fan/82/990466.html

版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。

标签:问题   查询   字符串   函数   写成   绑定   不能
相关文章
留言与评论(共有 0 条评论)
   
验证码:
推荐文章
排行榜
Copyright ©2019-2022 Comsenz Inc.Powered by © 专利检索| 网站地图