1 2 3 4 5 6 | <!--Mybatis动态SQL中使用Like语句--> select * from person where name like "%"#{name}"%" <!--推荐使用--> select * from person where name like '%'||#{name}||'%' select * from person where name like '%${name}%' |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 | public class ArticleSQLProvider { private final static String TABLE_NAME = "t_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(); } } |
联系客服