首先,分页  很简单.

1前台extjs数据源,

var shipMgrStore = Ext.create('Ext.data.Store', {
model: 'App.ShipMgr.model.ShipModel',
autoLoad: true,
pageSize: 15,
// timeout: 300000,
// simpleSortMode:true,
proxy: {
type: 'ajax',
url:'<%=request.getContextPath()%>/getDuncanJiang.action',
reader: {
reader: 'json',
root: 'sfdcConfigList',
totalProperty: 'totalProperty'
},
},
});

其他的属性就不说了.

主要是两个参数:一个是   root  :表示接收到的数据从这个   sfdcConfigLIst  开始解析

                 一个是 totalProperty   :表示返回数据的总行数

2 grid

var shipMgrGrid = Ext.create('Ext.grid.Panel', {
store: shipMgrStore,
columnLines: true,
rowLines: true,
region: 'center',
autoScroll: true,
forceFit: true,
loadMask: true,
border: true,
renderTo:'showPanel',
bbar: Ext.create('Ext.toolbar.Paging', {
id:'<portlet:namespace />bbar',
store: shipMgrStore,
pageSize:15,
displayInfo: true
}),
columns: [
Ext.create('Ext.grid.RowNumberer', {
text: 'numbr',
width: 50
}), {
text: 'id',
dataIndex: 'id'
}
, {
text: 'plant',
dataIndex: 'plant'
}, {
text: 'deviceId',
dataIndex: 'deviceId'
}, {
text: 'sfdcPort',
dataIndex: 'sfdcPort'
}, {
text: 'description',
dataIndex: 'description'
}
],
bbar: Ext.create('Ext.toolbar.Paging', {
id: '<portlet:namespace />duncanjiangbbar',
pageSize: 15,
store: shipMgrStore,
displayInfo: true,
displayMsg: '<%= bundle.getString("message.records") %> {0} - {1} of {2}',
emptyMsg: '<%= bundle.getString("page.nodata") %>'
})
});

传递二个参数 limit : 每页显示多少条 (pageSize)

       start :从第几条数据开始 (自动传递)

  当你在前台点击下一页的时候,它就会自动把 limit 和 start 传到后台查询数据,然后返回对面页的数据过来

后台的话 


private int start;
  //get  set
   private int limit;

  //get set

public String findSfdcByDeviceId(){
try {
int limit=this.limit;
int start=this.start;
    // 根据传过来的参数,查询数据
  this.fileNameList=testService.getSfdcCOnfigObjbyDeviceId(type,start,limit);
   //总条数
totalProperty=testService.getSfdcCOunt(type); }

其实就是 返回 两个数据集,一个是  fileNameList,当页数据, totalPropery是总共有多少条数据.

 定义属性接收前台传过来的 limit,start,并且生成get,set方法

&&&&&&&&&&&&&&&我是傲娇的分割线&&&&&&&&&&&&&&&&&&&&&&&

 然后做这个分页的时候还遇上一个问题,返回的 JSON数据到前台的时候报了一个错

html><head><title>Apache Tomcat/7.0.39 - Error report</title><style><!--H1 {font-family:Tahoma,Arial,sans-serif;color:white;background-color:#525D76;font-size:22px;} H2 {font-family:Tahoma,Arial,sans-serif;color:white;background-color:#525D76;font-size:16px;} H3 {font-family:Tahoma,Arial,sans-serif;color:white;background-color:#525D76;font-size:14px;} BODY {font-family:Tahoma,Arial,sans-serif;color:black;background-color:white;} B {font-family:Tahoma,Arial,sans-serif;color:white;background-color:#525D76;} P {font-family:Tahoma,Arial,sans-serif;background:white;color:black;font-size:12px;}A {color : black;}A.name {color : black;}HR {color : #525D76;}--></style> </head><body><h1>HTTP Status 500 - org.apache.struts2.json.JSONException: org.apache.struts2.json.JSONException: org.apache.struts2.json.JSONException: org.apache.struts2.json.JSONException: org.apache.struts2.json.JSONException: java.lang.IllegalAccessException: Class org.apache.struts2.json.JSONWriter can not access a member of class org.apache.commons.dbcp.PoolingDataSource$PoolGuardConnectionWrapper with modifiers &quot;public&quot;</h1><HR size="1" noshade="noshade"><p><b>type</b> Exception report</p><p><b>message</b> <u>org.apache.struts2.json.JSONException: org.apache.struts2.json.JSONException: org.apache.struts2.json.JSONException: org.apache.struts2.json.JSONException: org.apache.struts2.json.JSONException: java.lang.IllegalAccessException: Class org.apache.struts2.json.JSONWriter can not access a member of class org.apache.commons.dbcp.PoolingDataSource$PoolGuardConnectionWrapper with modifiers &quot;public&quot;</u></p><p><b>description</b> <u>The server encountered an internal error that prevented it from fulfilling this request.</u></p><p><b>exception</b> <pre>org.apache.struts2.json.JSONException: org.apache.struts2.json.JSONException: org.apache.struts2.json.JSONException: org.apache.struts2.json.JSONException: org.apache.struts2.json.JSONException: org.apache.struts2.json.JSONException: java.lang.IllegalAccessException: Class org.apache.struts2.json.JSONWriter can not access a member of class org.apache.commons.dbcp.PoolingDataSource$PoolGuardConnectionWrapper with modifiers &quot;public&quot;
org.apache.struts2.json.JSONWriter.bean(JSONWriter.java:243)
org.apache.struts2.json.JSONWriter.process(JSONWriter.java:165)
org.apache.struts2.json.JSONWriter.value(JSONWriter.java:131)
org.apache.struts2.json.JSONWriter.write(JSONWriter.java:99)
org.apache.struts2.json.JSONUtil.serialize(JSONUtil.java:112)
org.apache.struts2.json.JSONResult.execute(JSONResult.java:198)
com.opensymphony.xwork2.DefaultActionInvocation.executeResult(DefaultActionInvocation.java:362)
com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:266)
com.opensymphony.xwork2.interceptor.DefaultWorkflowInterceptor.doIntercept(DefaultWorkflowInterceptor.java:165)
com.opensymphony.xwork2.interceptor.MethodFilterInterceptor.intercept(MethodFilterInterceptor.java:87)
com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:237)
com.opensymphony.xwork2.validator.ValidationInterceptor.doIntercept(ValidationInterceptor.java:252)
org.apache.struts2.interceptor.validation.AnnotationValidationInterceptor.doIntercept(AnnotationValidationInterceptor.java:68)
com.opensymphony.xwork2.interceptor.MethodFilterInterceptor.intercept(MethodFilterInterceptor.java:87)
com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:237)
com.opensymphony.xwork2.interceptor.ConversionErrorInterceptor.intercept(ConversionErrorInterceptor.java:122)
com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:237)
com.opensymphony.xwork2.interceptor.ParametersInterceptor.doIntercept(ParametersInterceptor.java:195)
com.opensymphony.xwork2.interceptor.MethodFilterInterceptor.intercept(MethodFilterInterceptor.java:87)
com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:237)
com.opensymphony.xwork2.interceptor.ParametersInterceptor.doIntercept(ParametersInterceptor.java:195)
com.opensymphony.xwork2.interceptor.MethodFilterInterceptor.intercept(MethodFilterInterceptor.java:87)
com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:237)
com.opensymphony.xwork2.interceptor.StaticParametersInterceptor.intercept(StaticParametersInterceptor.java:179)
com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:237)
org.apache.struts2.interceptor.MultiselectInterceptor.intercept(MultiselectInterceptor.java:75)
com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:237)
org.apache.struts2.interceptor.CheckboxInterceptor.intercept(CheckboxInterceptor.java:94)
com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:237)
org.apache.struts2.interceptor.FileUploadInterceptor.intercept(FileUploadInterceptor.java:235)
com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:237)

这个是由于后台返回前台的数据中,会包含所有的get开头的,包括你的get属性,get开头的方法等等等等.导致的问题.

解决 : 1.在这些不需要返回的get方法的前面加上@JSON(serialize=false)这个注解.

     2.把查询返回的数据集做一个简单的处理,通过gson进行解析.具体为什么要这样....我也不清楚..... 哈哈哈哈,反正这样就可以了

public String findSfdcByDeviceId(){
try {
int limit=this.limit;
int start=this.start;
this.fileNameList=testService.getSfdcCOnfigObjbyDeviceId(type,start,limit);
Gson gson=new Gson();
List<SfdcConfigObj> rs=new ArrayList<SfdcConfigObj>();
String str=JSONArray.fromObject(fileNameList).toString();
Type ortype = new TypeToken<ArrayList<SfdcConfigObj>>() {}.getType();
rs=gson.fromJson(str, ortype);
for(SfdcConfigObj sfdc : rs){
sfdcConfigList.add(sfdc);
} totalProperty=testService.getSfdcCOunt(type); } catch (Exception e) {
e.printStackTrace();
} return Action.SUCCESS;
}

注意!!!   如果你要返回的,比如一个属性,暂且叫他为   number.这时候他的get方法如果你也加了这个注解的话,那么前台是获取不到这个值的.

extjs +String2 +Spring 下的分页 以及返回json格式错误的问题的更多相关文章

  1. spring 4.x下让http请求返回json串

    当前很多应用已经开始将响应返回为json串,所以基于springframework框架开发的服务端程序,让响应返回json字符串成为了一种常用手段. 这里介绍一下如何在spring-MVC框架下方便快 ...

  2. Spring MVC 学习笔记11 —— 后端返回json格式数据

    Spring MVC 学习笔记11 -- 后端返回json格式数据 我们常常听说json数据,首先,什么是json数据,总结起来,有以下几点: 1. JSON的全称是"JavaScript ...

  3. Spring Boot教程(二十五)返回JSON格式

    在上述例子中,通过@ControllerAdvice统一定义不同Exception映射到不同错误处理页面.而当我们要实现RESTful API时,返回的错误是JSON格式的数据,而不是HTML页面,这 ...

  4. SpringMVC通过实体类返回json格式的字符串,并在前端显示

    一.除了搭建springmvc框架需要的jar包外,还需要这两个jar包 jackson-core-asl-1.9.2.jar和jackson-mapper-asl-1.9.2.jar 二.web,. ...

  5. 【django后端分离】mysql原生查询命令后,RawQueryset类型的自定义序列化返回json格式

    1:设置mysql原生分页 # 监控系统首页显示分页 def MyPagination(limitid,offsetid): limitid =str(limitid) offsetid =str(o ...

  6. webapi返回json格式优化

    一.设置webapi返回json格式 在App_Start下的WebApiConfig的注册函数Register中添加下面这代码 config.Formatters.Remove(config.For ...

  7. ajax访问服务器返回json格式

    使用ajax访问服务器返回多条数据,比如返回一个表中的所有数据,页面该如何处理呢?如何获取数据呢?一直不会用ajax返回json格式,今天研究了下,分享给大家~ 首先需要引用服务,点击项目右键,添加引 ...

  8. webapi返回json格式,并定义日期解析格式

    1.webapi返回json格式 var json = config.Formatters.JsonFormatter; json.SerializerSettings.PreserveReferen ...

  9. 返回JSON格式(二十五)

    在上述例子中,通过@ControllerAdvice统一定义不同Exception映射到不同错误处理页面.而当我们要实现RESTful API时,返回的错误是JSON格式的数据,而不是HTML页面,这 ...

随机推荐

  1. Springboot中使用Scheduled做定时任务

    在开发中,定时任务是常见的功能,在spring boot 下开发定时任务其实很简单,具体代码如下: 1.配置依赖包pom.xml 由于默认的maven仓库经常访问不了,这里采用了阿里云的maven仓库 ...

  2. oracle 删除重复记录

    查询及删除重复记录的SQL语句   1.查找表中多余的重复记录,重复记录是根据单个字段(Id)来判断   select * from 表 where Id in (select Id from 表 g ...

  3. Petrozavodsk Summer-2017. Warsaw U Contest

    A. Connectivity 设$f[i][j]$为第$i$张图中$j$点所在连通块的编号,加边时可以通过启发式合并在$O(dn\log n)$的时间内维护出来. 对于每个点,设$h[i]$为$f[ ...

  4. dagger2 依赖注入

    前言: 当 mvp + dagger2 + rxjava 三者遇上,架构更加清晰,代码更加灵活,巧妙结合. 依赖注入:是为了解耦,达到高内聚低耦合的目的,保证代码的健壮性.灵活性和可维护性. publ ...

  5. 运用JS判断代码可以参考学习

    JAVAScript代码加CSS和HTML <%-- Created by IntelliJ IDEA. User: zengxiangcai Date: 2018/6/27 Time: 11: ...

  6. ubuntu下安装和配置pycharm和pyqt5

    参考网址:https://blog.csdn.net/qq_37541097/article/details/80021315 PyQt是Python语言的GUI编程解决方案之一.可以用来代替Pyth ...

  7. spring boot异常积累

    1.异常:Error resolving template "xxx", template might not exist or might not be accessible.. ...

  8. vs代码模板制作

    VS2008代码模板制作 一,类模板制作: 路径:C:\Program Files (x86)\Microsoft Visual Studio 9.0\Common7\IDE\ItemTemplate ...

  9. 学习ActiveMQ(八):activemq消息的持久化

    1. 持久化方式介绍前面我们也简单提到了activemq提供的插件式的消息存储,在这里再提一下,主要有以下几种方式: AMQ消息存储-基于文件的存储方式,是activemq开始的版本默认的消息存储方式 ...

  10. mysql 数据库的数据类型