<!-- 思想:把choose,when,otherwise,当做if-else来用 -->
<if test="dateType != null">
<choose>
<when test="dateType == 123">
AND sh.holiday_type IN (1,2,3)
<if test="dateName != '全部'.toString()">
AND sh.holiday_name=#{dateName}
</if>
</when>
<otherwise>
AND sh.holiday_type IS NULL
<if test="dateName != '全部'.toString()">
AND (select DAYNAME(a.register_time))=#{dateName}
</if>
</otherwise>
</choose>
</if>
使用Mybatis的时候,特殊字符需进行转义,如
不等于 <>
& &
< <
> >
" "
' '
小于等于 <=
大于等于 >=
<!-- 判断startDate与endDate 是否为空 -->
<where>
<if test="startDate != '' and endDate != ''">
DATE( register_time ) BETWEEN #{startDate} AND #{endDate}
</if>
</where>