Mybatis模糊查询like语句该怎么写

2022-07-29,,,,

(1)’%${question}%’ 可能引起SQL注入,不推荐

(2)"%"#{question}"%" 注意:因为#{…}解析成sql语句时候,会在变量外侧自动加单引号’ ',所以这里 % 需要使用双引号" ",不能使用单引号 ’ ',不然会查不到任何结果。

(3)CONCAT(’%’,#{question},’%’) 使用CONCAT()函数,推荐

(4)使用bind标签

<select id="listUserLikeUsername" resultType="com.jourwon.pojo.User">
  <bind name="pattern" value="'%' + username + '%'" />
  select id,sex,age,username,password from person where username LIKE #{pattern}
</select>

 

本文地址:https://blog.csdn.net/t194978/article/details/109000432

《Mybatis模糊查询like语句该怎么写.doc》

下载本文的Word格式文档,以方便收藏与打印。