7 . 动态sql-choose

choose-when-otherwise
只能满足一个when 中的条件,互斥的条件,不能同时存在
mapper.xml
<select id="selectstateByTitleOrstyle" parameterType="Blog" resultMap="blogResultMap" >
select * from blog where state = "1"
<choose>
<when test="title != null and title != ''">
and title like #{title}
</when>
<when test="style != null and style != ''">
and style = #{style}
</when>
<otherwise>
and featured = "1"
</otherwise>
</choose>
</select>
 实际应用:
 <choose>
             <when test="page !=null and page.orderBy != null and page.orderBy != ''">
                 ORDER BY ${page.orderBy}
             </when>
             <otherwise>
                 ORDER BY a.update_date DESC
             </otherwise>
         </choose>
上一篇:centos solr 集群搭建


下一篇:solr集群搭建(复制)