From d594d5053efe705b025445bd2ec61fce2a2954d5 Mon Sep 17 00:00:00 2001 From: Looly Date: Fri, 26 May 2023 23:32:29 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8DAbstractDb#page=E5=88=86?= =?UTF-8?q?=E9=A1=B5=E6=9F=A5=E8=AF=A2=E5=BC=82=E5=B8=B8=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- CHANGELOG.md | 3 +- .../main/java/cn/hutool/db/AbstractDb.java | 5 ++- .../java/cn/hutool/db/IssueI73770Test.java | 40 +++++++++++++++++++ 3 files changed, 46 insertions(+), 2 deletions(-) create mode 100644 hutool-db/src/test/java/cn/hutool/db/IssueI73770Test.java diff --git a/CHANGELOG.md b/CHANGELOG.md index 29fc845fb4..c6dfe99e2f 100755 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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) diff --git a/hutool-db/src/main/java/cn/hutool/db/AbstractDb.java b/hutool-db/src/main/java/cn/hutool/db/AbstractDb.java index fcccb7c978..beee6c8a49 100755 --- a/hutool-db/src/main/java/cn/hutool/db/AbstractDb.java +++ b/hutool-db/src/main/java/cn/hutool/db/AbstractDb.java @@ -889,7 +889,10 @@ public T page(CharSequence sql, Page page, RsHandler rsh, Object... param * @since 5.8.11 */ public PageResult page(CharSequence sql, Page page, Class elementBeanType, Object... params) throws SQLException { - return page(sql, page, (RsHandler>) rs -> HandleHelper.handleRsToBeanList(rs, new PageResult<>(page.getPageNumber(), page.getPageSize(), (int) count(sql, params)), elementBeanType), params); + final PageResult result = new PageResult<>(page.getPageNumber(), page.getPageSize(), (int) count(sql, params)); + return page(sql, page, + (RsHandler>) rs -> HandleHelper.handleRsToBeanList(rs, result, elementBeanType), + params); } /** diff --git a/hutool-db/src/test/java/cn/hutool/db/IssueI73770Test.java b/hutool-db/src/test/java/cn/hutool/db/IssueI73770Test.java new file mode 100644 index 0000000000..bce31d62ed --- /dev/null +++ b/hutool-db/src/test/java/cn/hutool/db/IssueI73770Test.java @@ -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 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; + } +}