Mybatis中的like查詢

源: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傳值的問題啊

如果不是字符串就沒法替換了
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章