首页 > 数据库技术 > 详细

【Mybatis】Mybatis的sql模糊查询

时间:2017-05-02 19:04:29      阅读:331      评论:0      收藏:0      [点我收藏+]

这个网站中有很多方法。https://code.google.com/p/mybatis/issues/detail?id=85

自己试验了如下的方法。

 

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

【Mybatis】Mybatis的sql模糊查询

原文:http://www.cnblogs.com/dflmg/p/6797501.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!