Make the page number to be 1 when the value equal to 0.

This commit is contained in:
peng-yongsheng 2018-03-05 20:27:59 +08:00
parent de81e2115d
commit 87c0f73e10
2 changed files with 8 additions and 1 deletions

View File

@ -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);
}

View File

@ -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);