"1.  java代码参数中直接加入%% param.setUsername('%xiaoming%'); param.setPassword('%111111%');"

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}),'%')

 

0   2   0   0   0  
3 回帖  
  • lyz API • 8 个月前

    0   0   0  
  • 88250 • 8 个月前

    谢谢分享~

    0   0   0  
  • lyz API • 8 个月前

    0   0   0