Mybatis中的like查询

源:http://blog.csdn.net/zhang98722/article/details/6956571

评:

今天要做一个模糊查询

用的Mybatis

开始写的是:

[html]viewplaincopy

selectid,bookName,author,publisher,donor,status,createDate,lastUpdatefrombook

<where>

<iftest="bookName!=null">

bookNamelike'%#{bookName}%'

</if>

<iftest="author!=null">

andauthorlike'%#{author}%'

</if>

最后改为:

[html]viewplaincopy

selectid,bookName,author,publisher,donor,status,createDate,lastUpdatefrombook

<where>

<iftest="bookName!=null">

bookNamelikeCONCAT('%','${bookName}','%')

</if>

<iftest="author!=null">

andauthorlikeCONCAT('%','${author}','%')

</if>

主要还是MyBatis传值的问题啊

如果不是字符串就没法替换了

相关推荐