MyBatis的Example如何按條件進行排序?
背景:有時我們在使用mybatis example 進行查詢時,需要進行相應的業務排序。本博客以下圖為例

@Override
    public List<Paper> viewPaperAll()
    {
        PaperExample paperExample = new PaperExample();
        //以創建時間為條件進行倒序
        paperExample.setOrderByClause("`creationDate` desc");
        List<Paper> paperList = paperMapper.selectByExample(paperExample);
        return paperList;
    }
 
        paperExample.setOrderByClause("creationDate desc"); //添加降序排列條件,desc為降序
那么要是業務需要多條件進行排序呢?
//多條件以逗號隔開,后接條件即可。
paperExample.setOrderByClause("creationDatedesc,modifyDatedesc");
效果顯示:

