MyBatis模糊查询like

时间:2015-10-18 16:41:07   收藏:0   阅读:291

 

MyBatis模糊查询like的两种使用方法

初次使用MyBatis持久层框架,进行模糊查询如like时,如果传入的map类型的参数,可以使用${}, 如果传入的不是map类型的参数, 不知道如何处理。经过研究想到了两种方法(我使用的是MySQL数据库), 如where name like concat(concat(‘%’#{name}),’%’)或者where name like “%”#{name}“%“注意:后一种方法”%”是双引号,而不是单引号

where bo.name like concat(concat(‘%‘, ?), ‘%‘) 

即完整的查找语句 

<select id="findByLikeName" parameterType="string" resultMap="bookMap">
    select id, name, bo.publisher
    from t_book 
    where name like concat(concat(‘%‘, #{name}),‘%‘)	
</select> 

 

原文:http://www.cnblogs.com/runhang/p/4889571.html

评论(0
© 2014 bubuko.com 版权所有 - 联系我们:wmxa8@hotmail.com
打开技术之扣,分享程序人生!