Mybatis
1.如何在Mybatis的xml映射文件中写like模糊查询?
(1)表达式: name like '%${name}%'
生成SQL:select * from bbs_brand where name like '%名字%'
使用$进行字符串的拼接,直接把传入的值,拼接上去了,没有任何问题。
(2)表达式: name like concat(concat('%',#{username}),'%')
生成SQL:select * from bbs_brand where name like concat(concat('%','名字'),'%')
这是使用了cancat进行字符串的连接,同时使用了#进行占位。
(3)表达式:name like concat('%','${name}','%')
生成SQL:select * from bbs_brand where name like concat('%','名字','%')
对上面的表达式进行了简化,更方便了。