mirror of
https://gitee.com/chinabugotech/hutool.git
synced 2025-07-21 15:09:48 +08:00
修复AbstractDb#page分页查询异常问题
This commit is contained in:
@@ -889,7 +889,10 @@ public abstract class AbstractDb implements Serializable {
|
||||
* @since 5.8.11
|
||||
*/
|
||||
public <T> PageResult<T> page(CharSequence sql, Page page, Class<T> elementBeanType, Object... params) throws SQLException {
|
||||
return page(sql, page, (RsHandler<? extends PageResult<T>>) rs -> HandleHelper.handleRsToBeanList(rs, new PageResult<>(page.getPageNumber(), page.getPageSize(), (int) count(sql, params)), elementBeanType), params);
|
||||
final PageResult<T> result = new PageResult<>(page.getPageNumber(), page.getPageSize(), (int) count(sql, params));
|
||||
return page(sql, page,
|
||||
(RsHandler<? extends PageResult<T>>) rs -> HandleHelper.handleRsToBeanList(rs, result, elementBeanType),
|
||||
params);
|
||||
}
|
||||
|
||||
/**
|
||||
|
40
hutool-db/src/test/java/cn/hutool/db/IssueI73770Test.java
Normal file
40
hutool-db/src/test/java/cn/hutool/db/IssueI73770Test.java
Normal file
@@ -0,0 +1,40 @@
|
||||
/*
|
||||
* Copyright (c) 2023 looly(loolly@aliyun.com)
|
||||
* Hutool is licensed under Mulan PSL v2.
|
||||
* You can use this software according to the terms and conditions of the Mulan PSL v2.
|
||||
* You may obtain a copy of Mulan PSL v2 at:
|
||||
* http://license.coscl.org.cn/MulanPSL2
|
||||
* THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
|
||||
* EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
|
||||
* MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
|
||||
* See the Mulan PSL v2 for more details.
|
||||
*/
|
||||
|
||||
package cn.hutool.db;
|
||||
|
||||
import lombok.Data;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
|
||||
import java.sql.SQLException;
|
||||
|
||||
/**
|
||||
* https://gitee.com/dromara/hutool/issues/I73770
|
||||
*/
|
||||
public class IssueI73770Test {
|
||||
@Test
|
||||
public void pageTest() throws SQLException {
|
||||
final PageResult<User> result = Db.use()
|
||||
.page("select * from user where id = ?"
|
||||
, new Page(0, 10), User.class, 9);
|
||||
|
||||
Assert.assertEquals(1, result.size());
|
||||
Assert.assertEquals(Integer.valueOf(9), result.get(0).getId());
|
||||
}
|
||||
|
||||
@Data
|
||||
static class User {
|
||||
private Integer id;
|
||||
private String name;
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user