zoukankan      html  css  js  c++  java
  • mybatis模糊查询拼接查询语句

    三种方式:

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

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

    4、原样输出$

    where username LIKE '%${username}%'



  • 相关阅读:
    函数式编程
    高级特性
    ZooKeeper介绍
    perl 退出函数问题
    perl 处理 回车 换行符
    定义函数
    调用函数
    python 字典
    python 条件判断
    列表和数组
  • 原文地址:https://www.cnblogs.com/xcggdd/p/7121507.html
Copyright © 2011-2022 走看看