1、java entity
/**
* 排序字段
*/
private String sortField;
/**
* 排序方式
*/
private String sortDirection;
2、mapper.xml
<if test="sortField == 'publish_time' and sortDirection =='desc'">
order by a.publish_time desc
</if>
<if test="sortField == 'publish_time' and sortDirection =='asc'">
order by a.publish_time asc
</if>
<if test="sortField == '' or sortField == null or sortDirection =='' or sortDirection == null">
order by a.create_time desc
</if>