<select id="findBlog" 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>
where标签可以去除 额外 and / or
<trim prefix="WHERE" prefixOverrides="AND |OR "> ... </trim>