Mybatis模糊查询(like)

Posted Jakeylove3

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Mybatis模糊查询(like)相关的知识,希望对你有一定的参考价值。

1.  参数中直接加入%%

param.setUsername("%CD%");
param.setPassword("%11%");

	<select  id="selectPersons" resultType="person" parameterType="person">
		select id,sex,age,username,password from person where true 
			<if test="username!=null"> AND username LIKE #{username}</if>
			<if test="password!=null">AND password LIKE #{password}</if>
	</select>

2.  bind标签

<select id="selectPersons" resultType="person" parameterType="person">
  <bind name="pattern" value="‘%‘ + _parameter.username + ‘%‘" />
  select id,sex,age,username,password 
  from person
  where username LIKE #{pattern}
</select>

3. CONCAT拼接sql

where username LIKE concat(concat(‘%‘,#{username}),‘%‘)

以上是关于Mybatis模糊查询(like)的主要内容,如果未能解决你的问题,请参考以下文章

mybatis模糊查询防止SQL注入

mybatis参数date怎么模糊查询

mybatis-plus模糊查询

Mybatis,模糊查询语句,以及传参数的正确写法

java mybatis 分页模糊查询页面怎么写

mybatis中的模糊查询