mybatis中排序操作,按用户或时间排序,且各自正序还是逆序条件

 

        <if test="timeType != null and timeType == 1 and isSort == 1">
            order by a.PUBLIC_TIME desc
        </if>
        <if test="timeType != null and timeType == 1 and isSort == 2">
            order by a.PUBLIC_TIME asc
        </if>
        <if test="timeType != null and timeType == 2 and isSort == 1">
            order by b.TURN_TIME desc
        </if>
        <if test="timeType != null and timeType == 2 and isSort == 2">
            order by b.TURN_TIME asc
        </if>
timeType 1. 发布时间,,2 提交时间
isSort 1, 升序,2降序
 <select id="query" resultMap="GhaExMyExamQueryVOMap">
        select
        a.EXAM_NAME ,a.PUBLIC_PEOPLE, a.PUBLIC_TIME, a.CANCEL_TIME,
        b.ID_,b.ISDELETED,b.TENANTID,b.OPTIME,b.OPER,b.UPDATETIME,b.UPDATOR,b.EXAMINE_ID,b.EXAM_STATUS,b.TURN_TIME,b.OPEN_TIME,b.EXAM_ID,b.SOURCE_INFORMATION,
        c.ID_ as id_, c.QUESTION_ID, c.MY_EXAM_ID,c.MY_ANSWER,c.QUESTION_TYPE,c.GAIN_SCORE as gainScore
        from gha_ex_my_exam b inner join gha_ex_exam a on a.ID_ = b.EXAM_ID
        left join gha_ex_answer_situation c on b.ID_ = c.MY_EXAM_ID and c.ISDELETED = '0'
        <where>
            a.ISDELETED = '0' and b.ISDELETED = '0'
            <if test="userid != null">
                and b.EXAMINE_ID = #{userid}
            </if>
            <if test="nameAndId != null and nameAndId != ''">
                 and (a.EXAM_NAME like concat('%',#{nameAndId},'%') or a.ID_ = #{nameAndId})
            </if>
            <if test="condition != null">
                 and b.EXAM_STATUS = #{condition}
            </if>
            <if test="userId != null">
                and a.PUBLIC_PEOPLE = #{userId}
            </if>
        </where>
        <if test="timeType != null and timeType == 1 and isSort == 1">
            order by a.PUBLIC_TIME desc
        </if>
        <if test="timeType != null and timeType == 1 and isSort == 2">
            order by a.PUBLIC_TIME asc
        </if>
        <if test="timeType != null and timeType == 2 and isSort == 1">
            order by b.TURN_TIME desc
        </if>
        <if test="timeType != null and timeType == 2 and isSort == 2">
            order by b.TURN_TIME asc
        </if>
    </select>

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值