DataTable分页时上送的数据为:
start - 开始的记录条数 , 从0开始 ;
length - 每页条数 ;
而
Spring data 的分页参数 PageRequest 的构造函数如下:
/**
* Creates a new unsorted {@link PageRequest}.
*
* @param page zero-based page index.
* @param size the size of the page to be returned.
* @since 2.0
*/
public static PageRequest of(int page, int size) {
return of(page, size, Sort.unsorted());
}
其中page 是第几页, size 的每页大小 , 显然第一个参数对不上, 需要转换下。
/**
* 转换datatable 开始条数到 PageRequest的页数
* @param start
* @param size
* @return
*/
private int dataTable2PageRequest(int start, int size) {
return (start + 1)/size;
}