项目搭建专栏:
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
排序前数据库
默认升序。
/***
*条件构造器 排序操作
*/
@Test
public void testEntitymapperOrderBy() {
List employeeList=employeeMapper.selectList(new EntityWrapper()
.eq("gender",1)
.like("name", "霸")
.orderBy("age")
);
System.out.println("*******************"+employeeList);
for (Employee employee : employeeList) {
System.out.println(employee.getAge());
}
}
SELECT id AS id,`name`,email,gender,age FROM employee WHERE (gender = ? AND name LIKE ?) ORDER BY age
注意其参数是一个column的集合。
代码修改为:
@Test
public void testEntitymapperOrderBy() {
List employeeList=employeeMapper.selectList(new EntityWrapper()
.eq("gender",1)
.like("name", "霸")
//.orderBy("age")
.orderDesc(Arrays.asList(new String[] {"age"}))
);
System.out.println("*******************"+employeeList);
for (Employee employee : employeeList) {
System.out.println(employee.getAge());
}
}
SELECT id AS id,`name`,email,gender,age FROM employee WHERE (gender = ? AND name LIKE ?) ORDER BY age DESC
注意其参数是一个column的集合。
升序排列。
代码测试:
@Test
public void testEntitymapperOrderBy() {
List employeeList=employeeMapper.selectList(new EntityWrapper()
.eq("gender",1)
.like("name", "霸")
//.orderBy("age")
//.last("desc")
//.orderDesc(Arrays.asList(new String[] {"age"}))
.orderAsc(Arrays.asList(new String[] {"age"}))
);
System.out.println("*******************"+employeeList);
for (Employee employee : employeeList) {
System.out.println(employee.getAge());
}
}
SELECT id AS id,`name`,email,gender,age FROM employee WHERE (gender = ? AND name LIKE ?) ORDER BY age ASC
https://download.csdn.net/download/badao_liumang_qizhi/11142313