1个回答
展开全部
//1.按照JqGrid的格式定义一个bean
public class JqGridData<T> {
//和JqGrid组件相关的参数属性
/**
* 查询返回的数组
*/
private List<T> gridModel=Collections.emptyList(); //得到实际数据的数组
private Integer rows=0; //每页中的记录行数
private Integer record=0; //总记录数
private Integer page=0; //当前页码数
private Integer total=0; //总页数
private String sord; //排序的方式
private String sidx; //用于排序的列名
private String search; //是否用于查询的请求
public List<T> getGridModel() {
return gridModel;
}
public void setGridModel(List<T> gridModel) {
this.gridModel = gridModel;
}
public Integer getRows() {
return rows;
}
public void setRows(Integer rows) {
this.rows = rows;
}
public Integer getRecord() {
return record;
}
public void setRecord(Integer record) {
this.record = record;
}
public Integer getPage() {
return page;
}
public void setPage(Integer page) {
this.page = page;
}
public Integer getTotal() {
return total;
}
public void setTotal(Integer total) {
this.total = total;
}
public String getSord() {
return sord;
}
public void setSord(String sord) {
this.sord = sord;
}
public String getSidx() {
return sidx;
}
public void setSidx(String sidx) {
this.sidx = sidx;
}
public String getSearch() {
return search;
}
public void setSearch(String search) {
this.search = search;
}
}
2.在Controller中返回数据:
//返回用户列表
@RequestMapping(value="/users",method=RequestMethod.GET)
public @ResponseBody JqGridData<User> loadUserList(@RequestParam("page") int from,@RequestParam("rows") int length,User user)
{
JqGridData<User> rst=new JqGridData<User>();
List<User> userList=new ArrayList<User>();
userList=ss.findUserList(from, length, user);
rst.setPage(from);
rst.setRows(length);
rst.setRecord(30);//此处要获取总记录数
rst.setTotal(10);//此处要做计算总页数
rst.setGridModel(userList);
return rst;
}
public class JqGridData<T> {
//和JqGrid组件相关的参数属性
/**
* 查询返回的数组
*/
private List<T> gridModel=Collections.emptyList(); //得到实际数据的数组
private Integer rows=0; //每页中的记录行数
private Integer record=0; //总记录数
private Integer page=0; //当前页码数
private Integer total=0; //总页数
private String sord; //排序的方式
private String sidx; //用于排序的列名
private String search; //是否用于查询的请求
public List<T> getGridModel() {
return gridModel;
}
public void setGridModel(List<T> gridModel) {
this.gridModel = gridModel;
}
public Integer getRows() {
return rows;
}
public void setRows(Integer rows) {
this.rows = rows;
}
public Integer getRecord() {
return record;
}
public void setRecord(Integer record) {
this.record = record;
}
public Integer getPage() {
return page;
}
public void setPage(Integer page) {
this.page = page;
}
public Integer getTotal() {
return total;
}
public void setTotal(Integer total) {
this.total = total;
}
public String getSord() {
return sord;
}
public void setSord(String sord) {
this.sord = sord;
}
public String getSidx() {
return sidx;
}
public void setSidx(String sidx) {
this.sidx = sidx;
}
public String getSearch() {
return search;
}
public void setSearch(String search) {
this.search = search;
}
}
2.在Controller中返回数据:
//返回用户列表
@RequestMapping(value="/users",method=RequestMethod.GET)
public @ResponseBody JqGridData<User> loadUserList(@RequestParam("page") int from,@RequestParam("rows") int length,User user)
{
JqGridData<User> rst=new JqGridData<User>();
List<User> userList=new ArrayList<User>();
userList=ss.findUserList(from, length, user);
rst.setPage(from);
rst.setRows(length);
rst.setRecord(30);//此处要获取总记录数
rst.setTotal(10);//此处要做计算总页数
rst.setGridModel(userList);
return rst;
}
追问
@RequestMapping("/getUsers.do")
public @ResponseBody List getUser() {
userList = this.userService.queryAll();
return userList;
}
controller里面我是这样写的,jqgrid里面不显示数据。
追答
你在火狐中用firebug看看返回的数据对不对?
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询