Make the page number to be 1 when the value equal to 0.
This commit is contained in:
parent
de81e2115d
commit
87c0f73e10
|
|
@ -28,7 +28,7 @@ public enum PaginationUtils {
|
|||
|
||||
public Page exchange(Pagination paging) {
|
||||
int limit = paging.getPageSize();
|
||||
int from = paging.getPageSize() * (paging.getPageNum() - 1);
|
||||
int from = paging.getPageSize() * ((paging.getPageNum() == 0 ? 1 : paging.getPageNum()) - 1);
|
||||
|
||||
return new Page(from, limit);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -37,6 +37,13 @@ public class PaginationUtilsTestCase {
|
|||
Assert.assertEquals(0, page.getFrom());
|
||||
Assert.assertEquals(10, page.getLimit());
|
||||
|
||||
pagination = new Pagination();
|
||||
pagination.setPageSize(10);
|
||||
|
||||
page = PaginationUtils.INSTANCE.exchange(pagination);
|
||||
Assert.assertEquals(0, page.getFrom());
|
||||
Assert.assertEquals(10, page.getLimit());
|
||||
|
||||
pagination = new Pagination();
|
||||
pagination.setPageSize(10);
|
||||
pagination.setPageNum(2);
|
||||
|
|
|
|||
Loading…
Reference in New Issue