sql语句 多条件排序

喜你入骨 提交于 2019-12-02 14:56:29
(1)入参为Map。
(2)Map中排序参数:
    sortName:排序字段。
    sortWay:排序方式。
(3)sql语句中的otherwise,两种情况:
    排序字段为空,默认一个排序字段。
    排序字段没找到,默认一个排序字段。

以下为排序的代码:
order by
<choose>
    <when test="params.sortName != null and params.sortWay!=null ">
        <choose>
            <when test='params.sortName=="name"'>name</when>
            <when test='params.sortName=="status"'>status</when>
            <when test='params.sortName=="gmtCreate"'>gmt_create</when>
            <!-- 排序字段没找到,默认一个排序字段-->
            <otherwise>
                gmt_create
            </otherwise>
        </choose>
        <if test=" params.sortWay=='asc'.toString()">ASC</if>
        <if test="params.sortWay=='desc'.toString()">DESC</if>
    </when>
    <!-- 排序字段为空,默认一个排序字段-->
    <otherwise>
        gmt_create DESC
    </otherwise>
</choose>
标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!