MyBatisPlus条件构造器实现降序排序的两种方式

场景

项目搭建专栏:

https://blog.csdn.net/BADAO_LIUMANG_QIZHI/column/info/37194

基础搭建:

https://blog.csdn.net/BADAO_LIUMANG_QIZHI/article/details/89407994

条件构造器介绍使用:

https://blog.csdn.net/BADAO_LIUMANG_QIZHI/article/details/89482201

实现

方式一:使用orderByDesc()方法

List employeeList=employeeMapper.selectList(new EntityWrapper()
    .eq("gender",1)
    .like("name", "霸")
    .orderDesc(Arrays.asList(new String[] {"age"}))
    );

方式二:使用orderBy()方法加last()方法

List employeeList=employeeMapper.selectList(new EntityWrapper()
    .eq("gender",1)
    .like("name", "霸")
    .orderBy("age")
    .last("desc")
    );

执行sql:

SELECT id AS id,`name`,email,gender,age FROM employee WHERE (gender = ? AND name LIKE ?) ORDER BY age desc

last()方法说明:

 

/**
     * 

     * 手动把sql拼接到最后(有sql注入的风险,请谨慎使用)      *

     *      * @param limit      * @return this      */     public Wrapper last(String limit) {         sql.LAST(limit);         return this;     }

 

你可能感兴趣的:(last方法,MyBatisPlus)