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标签

  官方APIblind标签介绍

bind

bind 元素可以从 OGNL 表达式中创建一个变量并将其绑定到上下文。比如:

<select id="selectPersons" resultType="person" parameterType="person">
  select id,sex,age,username,password,doi 
  from person
  where username = #{name}

  <if test="doi != null and '' != doi">
    <bind name="doiLike" value="'%' + doi + '%'" />
    and MPA.DOI LIKE #{doiLike}
  </if>

</select>

 

 

3. CONCAT

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

 



转http://www.cnblogs.com/cyttina/p/3894428.html
posted @ 2017-06-28 15:43  wdmiye  阅读(229)  评论(0编辑  收藏  举报