代码拉取完成,页面将自动刷新
在使用dubbo时,消费端RPC调用后端服务,消费端并没有任何连接数据库的权限,因此不需要引入mybatis依赖,此时后端返回的集合是分页插件的Page类,这个类引用了RowBounds,导致消费端反序列化Page类时,找不到RowBounds类。
From 2958c17800771fb313cb1acd150d087c11a7a133 Mon Sep 17 00:00:00 2001
From: "Jinkai.Ma" <majinkai@handu.com>
Date: Wed, 9 Sep 2015 16:44:59 +0800
Subject: [PATCH] =?UTF-8?q?=E4=B8=8D=E4=BE=9D=E8=B5=96RowBounds?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
src/main/java/com/github/pagehelper/Page.java | 17 +++++------------
src/main/java/com/github/pagehelper/SqlUtil.java | 6 ++----
2 files changed, 7 insertions(+), 16 deletions(-)
diff --git a/src/main/java/com/github/pagehelper/Page.java b/src/main/java/com/github/pagehelper/Page.java
index 314b9dc..4c30948 100644
--- a/src/main/java/com/github/pagehelper/Page.java
+++ b/src/main/java/com/github/pagehelper/Page.java
@@ -24,8 +24,6 @@
package com.github.pagehelper;
-import org.apache.ibatis.session.RowBounds;
-
import java.util.ArrayList;
import java.util.List;
@@ -105,23 +103,18 @@ public class Page<E> extends ArrayList<E> {
setReasonable(reasonable);
}
- public Page(RowBounds rowBounds, boolean count) {
- this(rowBounds, count ? Page.SQL_COUNT : Page.NO_SQL_COUNT);
- }
-
-
- public Page(RowBounds rowBounds, int total) {
+ public Page(int offset, int limit, int total) {
super(0);
- if (rowBounds.getOffset() == 0 && rowBounds.getLimit() == Integer.MAX_VALUE) {
+ if (offset == 0 && limit == Integer.MAX_VALUE) {
pageSizeZero = true;
this.pageSize = 0;
} else {
- this.pageSize = rowBounds.getLimit();
+ this.pageSize = limit;
}
- this.startRow = rowBounds.getOffset();
+ this.startRow = offset;
//RowBounds方式默认不求count总数,如果想求count,可以修改这里为SQL_COUNT
this.total = total;
- this.endRow = this.startRow + rowBounds.getLimit();
+ this.endRow = this.startRow + limit;
}
public List<E> getResult() {
diff --git a/src/main/java/com/github/pagehelper/SqlUtil.java b/src/main/java/com/github/pagehelper/SqlUtil.java
index 81e3675..241bcdf 100644
--- a/src/main/java/com/github/pagehelper/SqlUtil.java
+++ b/src/main/java/com/github/pagehelper/SqlUtil.java
@@ -294,10 +294,8 @@ public class SqlUtil implements Constant {
if (page == null) {
if (params instanceof RowBounds) {
RowBounds rowBounds = (RowBounds) params;
- if (offsetAsPageNum) {
- page = new Page(rowBounds.getOffset(), rowBounds.getLimit(), rowBoundsWithCount);
- } else {
- page = new Page(rowBounds, rowBoundsWithCount);
+ page = new Page(rowBounds.getOffset(), rowBounds.getLimit(), rowBoundsWithCount);
+ if (!offsetAsPageNum) {
//offsetAsPageNum=false的时候,由于PageNum问题,不能使用reasonable,这里会强制为false
page.setReasonable(false);
}
--
2.3.2 (Apple Git-55)
按照你这种方式修改后,实际调用的:
public Page(int pageNum, int pageSize, boolean count) {
this(pageNum, pageSize, count ? Page.SQL_COUNT : Page.NO_SQL_COUNT, null);
}
offset就直接当成了pageNum,所以不能直接这么改。
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。
Page类的构造方法由于1.0版本的原因,看着很乱。。
你有没有更好的修改方法?
不影响代码逻辑的话,可以提取出一个vo类,来代替RowBounds,但是看代码,只有SqlUtil.java的public Page getPage(Object params)使用到了,把方法参数改成int[]就行了,这样也不影响代码逻辑
状态更改为 已关闭
使用dubbo回调时,返回的list对象分页信息丢失,
原因:fastjson,hessian对对象继承实现Collection做了特殊实现,导致序列化时并未对属性进行序列化。
登录 后才可以发表评论