Mybatis specifies fields and ascending and descending sorting

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>

3. postman test

3.1、Headers

Insert image description here

3.2、Send

Insert image description here

Guess you like

Origin blog.csdn.net/docsz/article/details/128410501