mybatis做like模糊查询

1.  java 代码参数中直接加入 %%


param.setUsername("%xiaoming%");
param.setPassword("%111111%");


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

2.  bind 标签


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

</select>

3. CONCAT


select id,sex,age,username,password from org_user

where username LIKE concat(cancat('%',#{username}),'%')