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>