mybais xml 配置 格式
select * from person where name like "%"#{name}"%"<!--推荐使用-->
select * from person where name like '%'||#{name}||'%'
select * from person where name like '%${name}%'
Mybatis动态SQL中使用Like语句
java代码
public class ArticleSQLProvider {
private final static String TABLE_NAME = "tab_article";
public String findByArticle(final Article article){
return new SQL(){
{
SELECT("*");
FROM(TABLE_NAME);
if(article.getArticleId()!=null){
WHERE("articleId = #{articleId}");
}
if (article.getTitle()!=null){
WHERE("title like \"%\"#{title}\"%\"");
}
if(article.getContent()!=null){
WHERE("content like \"%\"#{content}\"%\"");
}
}
}.toString();
}
}