源:http://blog.youkuaiyun.com/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进行模糊查询的方法,通过对比不同的SQL语句,讲解了如何正确地传递参数并实现字符串匹配。
2万+

被折叠的 条评论
为什么被折叠?



