zoukankan      html  css  js  c++  java
  • MyBatis choose(when, otherwise)标签

    MyBatis choose(when, otherwise)标签

            有时候我们并不想应用所有的条件,而只是想从多个选项中选择一个。而使用if标签时,只要test中的表达式为 true,就会执行 if 标签中的条件。MyBatis 提供了 choose 元素。if标签是与(and)的关系,而 choose 是或(or)的关系。

            choose标签是按顺序判断其内部when标签中的test条件出否成立,如果有一个成立,则 choose 结束。当 choose 中所有 when 的条件都不满则时,则执行 otherwise 中的sql。类似于 的 switch 语句,choose 为 switch,when 为 case,otherwise 则为 default。

            下面是我写的一个例子:

    <choose>
     <when test="BEGINTIME != null and BEGINTIME != '' and ENDTIME != null and ENDTIME != ''">
     	AND time BETWEEN #{BEGINTIME, jdbcType=VARCHAR} AND #{ENDTIME, jdbcType=VARCHAR}
     </when>
     <when test="BEGINTIME != null and BEGINTIME != ''">
     	<![CDATA[ AND time  > #{BEGINTIME, jdbcType=TIMESTAMP} ]]>
     </when>
     <when test="ENDTIME != null and ENDTIME != ''">
     	<![CDATA[ AND time  < #{ENDTIME, jdbcType=TIMESTAMP} ]]>
     </when>
     <otherwise></otherwise>
    </choose>
  • 相关阅读:
    css布局模型
    HTML元素分类
    《水经注》卷三十五
    《水经注》卷二十八
    沧浪之水
    网页布局基础
    IndexError: tuple index out of range
    树回归-CART
    树回归-CART
    支持向量机SVM
  • 原文地址:https://www.cnblogs.com/new0801/p/6146653.html
Copyright © 2011-2022 走看看