mybatis作like模糊查詢

1.  參數中直接加入%%

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

<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(推薦用法)

where username LIKE concat(concat('%',#{username}),'%')
相關文章
相關標籤/搜索