mybatis的when⽤法
⼀、choose标签
choose标签在mybatis的xml⽂件中,⼀般与when标签结合使⽤,  主要⽤于条件查询,根据不同的情况来进⾏页⾯查询,choose的执
⾏原理如下: 如果有⼀个when满⾜,那么choose结束, choose会按照when标签的顺序来执⾏,如果when执⾏的结果都会false,那么会执⾏otherwise标签⾥的语句。
⼆、实例SQL
<choose>
<when test="range == 'all'">
<!-- 全选 -->
mysql语句的执行顺序AND 1 = 1
</when>
<when test="range == 'selected'">
<if test="documentType == 801012">
<!-- 费⽤预提单类型选择的-->
AND EXISTS (select 1 from exp_accrual_expense_type a p_accrual_type_id = #{documentTypeId} p_expense_id = t.id)
</if>
<if test="documentType == 801006">
tarzan去哪个队了<!-- 费⽤调整单类型选择的-->
AND EXISTS (select 1 from exp_adjust_type_assign_e_t a p_adjust_type_id = #{documentTypeId} p_expense_id = t.id)
</if>
<if test="documentType == 801001">
<!-- 报账单类型已选的费⽤类型-->
AND EXISTS (select 1 from exp_report_type_expense_type ertet port_type_id = #{documentTypeId} pense_type_id = t.id)
</if>
</when>
<otherwise>
<if test="documentType == 801012">
<!-- 费⽤预提单类型未选的-->
AND NOT EXISTS (select 1 from exp_accrual_expense_type a p_accrual_type_id = #{documentTypeId} p_expense_id = t.id)
</if>
<if test="documentType == 801006">
<!-- 费⽤调整单类型未选的-->
breeze from the seaAND NOT EXISTS (select 1 from exp_adjust_type_assign_e_t a p_adjust_type_id = #{documentTypeId} p_expense_id = t.id)
</if>
<if test="documentType == 801001">
<!-- 报账单类型未选的费⽤类型-->
AND NOT EXISTS (select 1 from exp_report_type_expense_type ertet port_type_id = #{documentTypeId} pense_type_id =
</if>exploitive
clear属性值</otherwise>
t字钢型钢型号图片
</choose>

版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。