码迷,mamicode.com
首页 > 其他好文 > 详细

Mybatis中的like查询

时间:2017-04-17 14:15:32      阅读:164      评论:0      收藏:0      [点我收藏+]

标签:creat   views   pop   soft   author   view   tools   htm   模糊查询   

今天要做一个模糊查询

用的Mybatis

开始写的是:

 

[html] view plain copy
 
  1. select id,bookName,author,publisher,donor,status,createDate,lastUpdate from book   
  2.         <where>  
  3.             <if test="bookName!=null">  
  4.                 bookName like ‘%#{bookName}%‘  
  5.             </if>  
  6.             <if test="author!=null">  
  7.                 and author like ‘%#{author}%‘  
  8.             </if>  



 

最后改为:

 

[html] view plain copy
 
  1. select id,bookName,author,publisher,donor,status,createDate,lastUpdate from book  
  2.         <where>  
  3.             <if test="bookName!=null">  
  4.                 bookName like CONCAT(‘%‘,‘${bookName}‘,‘%‘ )  
  5.             </if>  
  6.             <if test="author!=null">  
  7.                 and author like CONCAT(‘%‘,‘${author}‘,‘%‘ )  
  8.             </if>  

 

主要还是MyBatis传值的问题啊

如果不是字符串就没法替换了

详细源码更多技术支持来源查询:minglisoft.cn/technology

Mybatis中的like查询

标签:creat   views   pop   soft   author   view   tools   htm   模糊查询   

原文地址:http://www.cnblogs.com/itsuperman/p/6722491.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!