使用场景:多个条件中选择一个使用
如下列语句
类比我们学过的switch语句,只能选择一个
当title的值不为空时,就执行"select * from mybatis.blog where title=‘title’;“这个语句
当title和author都不为空时,执行第一个条件,即"select * from mybatis.blog where title=‘title’;”
当title和author为空时,一定要传**《otherwise》**这个标签的值,不然会报错
<!-- ************choose语句*************-->
<select id="queryBlogChoose" parameterType="map" resultType="Blog">
select * from mybatis.blog
<where>
<choose>
<when test="title !=null">
title =#{title}
</when>
<when test="author !=null">
and author=#{author}
</when>
<otherwise>
and views=#{views}
</otherwise>
</choose>
</where>
</select>