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>
  • 相关阅读:
    git忽略已提交过的文件方法
    去除git版本控制
    写博客的初衷
    Substring with Concatenation of All Words
    Course Schedule
    Reverse Words in a String--not finished yet
    Repeated DNA Sequences
    Maximum Product of Word
    Odd Even Linked List
    Reorder List
  • 原文地址:https://www.cnblogs.com/new0801/p/6146653.html
Copyright © 2011-2022 走看看