mybatis 避免 where 1=1

mybatis 避免 where 1=1

mybatis动态拼接条件的两种方式:
  • where 1=1
  • where标签

where标签方式:

<select id="findActiveBlogLike"  resultType="Blog">
    SELECT * FROM BLOG
    <where>
        <if test="state != null">
            state = #{state}
        </if>
        <if test="title != null">
            AND title like #{title}
        </if>
        <if test="author != null and author.name != null">
            AND author_name like #{author.name}
        </if>
    </where>
</select>
原文地址:https://www.cnblogs.com/muzhongjiang/p/12793964.html