您的位置:首页 > 其它

Mybatis中的like查询

2014-11-03 14:26 218 查看
转自:http://blog.csdn.net/zhang98722/article/details/6956571

今天要做一个模糊查询

用的Mybatis

开始写的是:

[html] view
plaincopy

select id,bookName,author,publisher,donor,status,createDate,lastUpdate from book   

        <where>  

            <if test="bookName!=null">  

                bookName like '%#{bookName}%'  

            </if>  

            <if test="author!=null">  

                and author like '%#{author}%'  

            </if>  

最后改为:

[html] view
plaincopy

select id,bookName,author,publisher,donor,status,createDate,lastUpdate from book  

        <where>  

            <if test="bookName!=null">  

                bookName like CONCAT('%','${bookName}','%' )  

            </if>  

            <if test="author!=null">  

                and author like CONCAT('%','${author}','%' )  

            </if>  

主要还是MyBatis传值的问题啊

如果不是字符串就没法替换了
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息