Skip to content

Commit

Permalink
修复AbstractDb#page分页查询异常问题
Browse files Browse the repository at this point in the history
  • Loading branch information
looly committed May 26, 2023
1 parent 791ba35 commit d594d50
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 2 deletions.
3 changes: 2 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,8 @@
* 【cron 】 修复SystemTimer无法结束进程问题(issue#3090@Github)
* 【core 】 修复BeanUtil.copyToList复制Long等类型错误问题(issue#3091@Github)
* 【poi 】 修复MapRowHandler结果Map无序问题(issue#I71SE8@Github)
* 【db 】 修复SqlExecutor.execute执行ORACLE insert into select报ORA-00933问题(issue#I778U7@Github)
* 【db 】 修复SqlExecutor.execute执行ORACLE insert into select报ORA-00933问题(issue#I778U7@Gitee)
* 【db 】 修复AbstractDb#page分页查询异常问题(issue#I73770@Gitee)

-------------------------------------------------------------------------------------------------------------
# 5.8.18 (2023-04-27)
Expand Down
5 changes: 4 additions & 1 deletion hutool-db/src/main/java/cn/hutool/db/AbstractDb.java
Original file line number Diff line number Diff line change
Expand Up @@ -889,7 +889,10 @@ public <T> T page(CharSequence sql, Page page, RsHandler<T> rsh, Object... param
* @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);
}

/**
Expand Down
40 changes: 40 additions & 0 deletions hutool-db/src/test/java/cn/hutool/db/IssueI73770Test.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
/*
* Copyright (c) 2023 looly([email protected])
* 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;
}
}

0 comments on commit d594d50

Please sign in to comment.