Loading

MyBatis的Example如何按条件排序(Day_35)

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("creationDate desc,modifyDate desc");

效果显示:

posted @ 2021-02-09 10:54  A零号  阅读(2584)  评论(0编辑  收藏  举报