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传值的问题啊
如果不是字符串就没法替换了
今天要做一个模糊查询
用的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传值的问题啊
如果不是字符串就没法替换了
相关文章推荐
- Mybatis中oracle、mysql、db2、sql server的like模糊查询
- mybatis做like模糊查询
- myBatis 操作 mysql时,使用 like 关键进行模糊查询的方法
- mybatis做like模糊查询
- Mybatis中的like查询
- Mybatis中的like查询
- Mybatis 的like模糊查询
- mybatis like 条件查询语句
- mybatis like查询常用两种写法
- Mybatis的like模糊查询
- mybatis做like模糊查询
- mybatis中的#和$的区别以及mybatis like查询
- mybatis做like模糊查询
- MyBatis的like模糊查询
- mybatis like 查询
- MyBatis SQLServer 模糊查询LIKE、本年、本月、近三月、近两月
- Mybatis中oracle、mysql、db2、sql server的like模糊查询
- Mybatis中oracle、mysql、db2、sql server的like模糊查询
- Mybatis模糊查询--like
- mybatis xml文件中的大于、小于、及like模糊查询的写法