mybatis中多条件判断---choose when的用法

    <select id="getFunctionByPage" resultMap="FunctionRlt">
        SELECT
        K.FUNCTION_NAME,K.FUNCTION_NO,K.URL,K.PARAM_CLASS,
        FROM PUB_FUNCTION K
        <choose>
            <when test="model.parentFuncName!= null and model.parentFuncName!= ''">
                ,PUB_FUNCTION PF WHERE K.PARENT_FUNCTION_ID=PF.FUNCTION_ID
                AND PF.FUNCTION_NAME LIKE '%'||#{model.parentFuncName}||'%'
                <if test="model.functionName != null and model.functionName != ''">
                    AND K.FUNCTION_NAME LIKE '%'||#{model.functionName}||'%'
                </if>
                <if test="model.functionType != null and model.functionType != ''">
                    AND K.FUNCTION_TYPE = #{model.functionType}
                </if>
                <if test="model.isMobile != null and model.isMobile != ''">
                    AND K.IS_MOBILE = #{model.isMobile}
                </if>
            </when>
            <!-- 根据父功能点获取子功能列表 -->
            <when test="model.functionId != null and model.functionId != ''">
                <where>
                    <choose>
                        <when test="model.functionId==000000L">
                            AND K.PARENT_FUNCTION_ID is null
                        </when>
                        <otherwise>
                            AND K.PARENT_FUNCTION_ID=#{model.functionId}
                        </otherwise>
                    </choose>
                </where>
            </when>
            <otherwise>
                <where>
                    <if test="model.functionName != null and model.functionName != ''">
                        AND K.FUNCTION_NAME LIKE
                        '%'||#{model.functionName}||'%'
                    </if>
                    <if test="model.functionType != null and model.functionType != ''">
                        AND K.FUNCTION_TYPE = #{model.functionType}
                    </if>
                    <if test="model.isMobile != null and model.isMobile != ''">
                        AND K.IS_MOBILE = #{model.isMobile}
                    </if>
                </where>
            </otherwise>
        </choose>
        <choose>
            <when test="sort != null and sort != '' and dir != null and dir != ''">
                ORDER BY ${sort} ${dir}
            </when>
            <otherwise>
                ORDER BY K.PARENT_FUNCTION_ID,K.FUNCTION_SEQ ASC
            </otherwise>
        </choose>
    </select>

 

转载于:https://www.cnblogs.com/StanLong/p/6392626.html

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值