import org.springframework.data.domain.Sort;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageImpl;
import org.springframework.data.domain.Sort.Direction;
...
int page = 0;
int count = 8;
String sortOrder = "desc";
String sortBy = "id";
Sort sort = new Sort(Direction.fromString(sortOrder),sortBy);
PageRequest pageable = new PageRequest(page,count,sort);
List
上面的脚本不会返回包含8个元素的页面.为什么?
注:列表没有从db返回
你能帮助我吗?
最佳答案
我解决了这个解决方法.
import org.springframework.data.domain.Sort;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageImpl;
import org.springframework.data.domain.Sort.Direction;
...
int page = 0;
int count = 8;
String sortOrder = "desc";
String sortBy = "id";
Sort sort = new Sort(Direction.fromString(sortOrder),sortBy);
PageRequest pageable = new PageRequest(page,sort);
List
我实现了一个新的自定义比较器类
import java.lang.reflect.Field;
import java.util.Comparator;
import java.util.Date;
public class MyListComparator implements Comparator