我是靠谱客的博主 疯狂薯片,这篇文章主要介绍Mybatis使用choose when,现在分享给大家,希望可以做个参考。

Mybatis使用<choose> <when>

例子: order by

  <sql id="Base_OrderBy">
    <if test="orderBy != null and orderBy.size() &gt; 0">
      order by
      <foreach collection="orderBy" item="item" separator=",">
        <choose>
          <when test="item.name == 'codeTabUuid'">
            CODE_TAB_UUID
            <if test="item.direction != null">
              ${item.direction}
            </if>
          </when>
          <when test="item.name == 'code'">
            CODE
            <if test="item.direction != null">
              ${item.direction}
            </if>
          </when>
          <when test="item.name == 'name'">
            NAME
            <if test="item.direction != null">
              ${item.direction}
            </if>
          </when>
          <when test="item.name == 'codeType'">
            CODE_TYPE
            <if test="item.direction != null">
              ${item.direction}
            </if>
          </when>
          <when test="item.name == 'parentUuid'">
            PARENT_UUID
            <if test="item.direction != null">
              ${item.direction}
            </if>
          </when>
          <when test="item.name == 'upLimit'">
            UP_LIMIT
            <if test="item.direction != null">
              ${item.direction}
            </if>
          </when>
          <when test="item.name == 'downLimit'">
            DOWN_LIMIT
            <if test="item.direction != null">
              ${item.direction}
            </if>
          </when>
          <when test="item.name == 'srcCode'">
            SRC_CODE
            <if test="item.direction != null">
              ${item.direction}
            </if>
          </when>
          <when test="item.name == 'srcName'">
            SRC_NAME
            <if test="item.direction != null">
              ${item.direction}
            </if>
          </when>
          <when test="item.name == 'srcParentCode'">
            SRC_PARENT_CODE
            <if test="item.direction != null">
              ${item.direction}
            </if>
          </when>
          <when test="item.name == 'sortValue'">
            SORT_VALUE
            <if test="item.direction != null">
              ${item.direction}
            </if>
          </when>
          <otherwise />
        </choose>
      </foreach>
    </if>
  </sql>

最后

以上就是疯狂薯片最近收集整理的关于Mybatis使用choose when的全部内容,更多相关Mybatis使用choose内容请搜索靠谱客的其他文章。

本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
点赞(137)

评论列表共有 0 条评论

立即
投稿
返回
顶部