fix PageUtil bug

This commit is contained in:
Looly
2020-03-13 16:18:11 +08:00
parent 98cbc875dc
commit a508f2d5aa
11 changed files with 128 additions and 33 deletions

View File

@@ -49,7 +49,7 @@ public class Page implements Serializable {
/**
* 构造
*
* @param pageNumber 页码
* @param pageNumber 页码0表示第一页
* @param numPerPage 每页结果数
* @param order 排序对象
*/
@@ -61,7 +61,7 @@ public class Page implements Serializable {
// ---------------------------------------------------------- Getters and Setters start
/**
* @return 页码
* @return 页码0表示第一页
*/
public int getPageNumber() {
return pageNumber;
@@ -157,10 +157,14 @@ public class Page implements Serializable {
/**
* 开始位置和结束位置<br>
* 例如:<br>
* 页码1每页10 =》 [0, 10]<br>
* 页码2每页10 =》 [10, 20]<br>
* 。。。<br>
* 例如:
*
* <pre>
* 页码0每页10 =》 [0, 10]
* 页码1每页10 =》 [10, 20]
* 页码2每页10 =》 [21, 30]
* 。。。
* </pre>
*
* @return 第一个数为开始位置,第二个数为结束位置
*/

View File

@@ -16,7 +16,7 @@ public class PageResult<T> extends ArrayList<T> {
public static final int DEFAULT_PAGE_SIZE = Page.DEFAULT_PAGE_SIZE;
/**
* 页码
* 页码0表示第一页
*/
private int page;
/**
@@ -44,7 +44,7 @@ public class PageResult<T> extends ArrayList<T> {
/**
* 构造
*
* @param page 页码
* @param page 页码0表示第一页
* @param pageSize 每页结果数
*/
public PageResult(int page, int pageSize) {
@@ -57,7 +57,7 @@ public class PageResult<T> extends ArrayList<T> {
/**
* 构造
*
* @param page 页码
* @param page 页码0表示第一页
* @param pageSize 每页结果数
* @param total 结果总数
*/
@@ -72,14 +72,16 @@ public class PageResult<T> extends ArrayList<T> {
//---------------------------------------------------------- Getters and Setters start
/**
* @return 页码
* 页码0表示第一页
*
* @return 页码0表示第一页
*/
public int getPage() {
return page;
}
/**
* 设置页码
* 设置页码0表示第一页
*
* @param page 页码
*/

View File

@@ -28,6 +28,15 @@ public class DbTest {
Assert.assertEquals("王五", find.get(0).get("name"));
}
@Test
public void pageTest() throws SQLException {
// 测试数据库中一共4条数据第0页有3条第1页有1条
List<Entity> page0 = Db.use().page(Entity.create("user"), 0, 3);
Assert.assertEquals(3, page0.size());
List<Entity> page1 = Db.use().page(Entity.create("user"), 1, 3);
Assert.assertEquals(1, page1.size());
}
@Test
public void findLikeTest() throws SQLException {
// 方式1

View File

@@ -1,15 +1,12 @@
package cn.hutool.db;
import java.sql.SQLException;
import java.util.List;
import cn.hutool.db.pojo.User;
import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;
import cn.hutool.db.Db;
import cn.hutool.db.Entity;
import cn.hutool.db.pojo.User;
import java.sql.SQLException;
import java.util.List;
/**
* Entity测试