实现
方式一:使用orderByDesc()方法
List<Employee> employeeList=employeeMapper.selectList(new EntityWrapper<Employee>()
.eq("gender",1)
.like("name", "霸")
.orderDesc(Arrays.asList(new String[] {"age"}))
);
方式二:使用orderBy()方法加last()方法
List<Employee> employeeList=employeeMapper.selectList(new EntityWrapper<Employee>()
.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()方法说明:
/**
* <p>
* 手动把sql拼接到最后(有sql注入的风险,请谨慎使用)
* </p>
*
* @param limit
* @return this
*/
public Wrapper<T> last(String limit) {
sql.LAST(limit);
return this;
}
标签:MyBatisPlus,name,gender,降序,sql,new,排序,age,last From: https://blog.51cto.com/BADAOLIUMANGQZ/6115622