zoukankan      html  css  js  c++  java
  • 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
  • 相关阅读:
    SJTU T4143 推箱子
    Markdown基本语法
    命令行的操作——cd
    C++ ------- 类和对象
    数据结构------栈和队列
    MySQL------ 子查询
    MySQL------ SQL99语法
    C++------内存分区模型
    第三章------数据链路层
    MySQL------ SQL92语法
  • 原文地址:https://www.cnblogs.com/miye/p/7090030.html
Copyright © 2011-2022 走看看