(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>
来源:https://blog.csdn.net/u012406790/article/details/102777816