<select id="getArticleInfo" resultMap="BaseResultMap">
select * from articleinfo where 1=1<if test="title!=null">
and title=#{title}</if><if test="content!=null">/*这个test中的content是mapper层传进来的@Param中设置的参数的值*/
and content=#{content}</if><if test="state!=0">
and state=#{state}</if></select>
测试结果
@TestvoidgetArticleInfo(){List<ArticleInfo> list = articleInfoMapper.getArticleInfo(null,null,0);
list.forEach(System.out::println);}
<select id="getArticleInfo2" resultMap="BaseResultMap">
select * from articleinfo
<trim prefix="where" prefixOverrides="and"><if test="title!=null">
and title=#{title}</if><if test="content!=null">
and content=#{content}</if><if test="state!=0">
and state=#{state}</if></trim></select>
<select id="getArticleInfo3" resultMap="BaseResultMap">
select * from articleinfo
<where><if test="title!=null">
and title=#{title}</if><if test="content!=null">
and content=#{content}</if><if test="state!=0">
and state=#{state}</if></where></select>