美文网首页
mybatis 动态SQL like模糊查询

mybatis 动态SQL like模糊查询

作者: 氕氘氚_笔记 | 来源:发表于2018-07-18 12:25 被阅读0次

方案一

<select id="selectPersons" resultType="person" parameterType="person">
  <bind name="pattern" value="'%' + _parameter.username + '%'" />
  select id,sex,age,username,password 
  from person
  where username LIKE #{pattern}
</select

方案二

使用 ${...} 代替 #{...}

   SELECT * FROM tableName WHERE name LIKE '%${text}%'; 

方案三

java 代码
             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}\"%\"");
 }

相关文章

网友评论

      本文标题:mybatis 动态SQL like模糊查询

      本文链接:https://www.haomeiwen.com/subject/ccdopftx.html