作者:手机用户2502884923 | 来源:互联网 | 2022-01-26 10:15
前台部分:
代码如下:
Ext.define('GS.system.role.store.RoleGridStore',{
extend:'Ext.data.Store',
model:'GS.system.role.model.RoleGridModel',
id:'roleStoreId',
pageSize:4,//分页大小
proxy:{
type:'ajax',
url:'/gs_erp/roleAction!getRoleList',
reader: {
type: 'json',
root: 'rows',
totalProperty: 'total'
}
},
sorters: [{
property: 'id', //排序字段
direction: 'asc'// 默认ASC
}],
autoLoad:{start: 0, limit: 4}//start是从第几条开始,limit是每页的条数
});
store.loadPage(1); //加载第一页
后台部分:
代码如下:
private int limit;//每一页的条数
private int start;//从哪一条数据开始查
private int total;//总条数
/**
* 查找所有角色
*/
public void getRoleList()
{
List roleList=new ArrayList();
StringBuffer toJson=new StringBuffer();//用来放json数据
System.out.println(start+","+limit+","+total);
try
{
roleList=(List) pageServiceImpl.commonPagination(Role.class, "", start, limit);
total=pageServiceImpl.getTotalNum(Role.class, "");
toJson.append("{total:").append(""+total+"").append(",success:true,").append("start:")
.append(""+start+"").append(",");
toJson.append("rows:[");
for(int i=0;i{
toJson.append("{id:").append("'").append(""+roleList.get(i).getId()+"").append("'")
.append(",name:").append("'").append(""+roleList.get(i).getName()+"")
.append("'").append(",desc:").append("'").append(""+roleList.get(i).getDesc()+"")
.append("'").append("}");
if(i{
toJson.append(",");
}
}
toJson.append("]}");
} catch (Exception e1)
{
// TODO Auto-generated catch block
e1.printStackTrace();
}
try
{
response.setHeader("Cache-Control", "no-cache");
response.setContentType("text/json;charset=utf-8");
response.getWriter().print(toJson);
System.out.println(toJson);
} catch (IOException e)
{
// TODO Auto-generated catch block
e.printStackTrace();
}
}