五、动态SQL(<choose><when><otherwise>)

一、<choose><when><otherwise>

这是一套标签, 功能类似于 switch...case...

 1 <select id="sel1" resultType="User">
 2         select * from tb_user
 3         <where>
 4             <choose>
 5                 <when test="user != null and user != ''">
 6                     and user = #{user}
 7                 </when>
 8                 <when test="passwd != null and passwd != ''">
 9                     and passwd = #{passwd}
10                 </when>
11                 <otherwise>
12                     and 1 = 1
13                 </otherwise>
14             </choose>
15         </where>
16 </select>      
原文地址:https://www.cnblogs.com/qiaoxin11/p/12855531.html