带有spring mvc的jqgrid json数据类型
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了带有spring mvc的jqgrid json数据类型相关的知识,希望对你有一定的参考价值。
我是jqgrid的新手,我试图模拟上面的代码,但它不起作用。在服务器端我创建了类
public class TaskBean {
String orderId;
String realty;
String building;
String priority;
String action;
String assignee; // add getter/setter methods
}
task bean list.Java
public class TaskBeanList {
private String page;
private String total;
private String records;
private List<TaskBean> rows;
}
弹簧控制器代码
@RequestMapping("/page4.htm")
public @ResponseBody TaskBeanList getJQGridData(HttpServletRequest request, HttpServletResponse response) {
System.out.println("xml data");
List<TaskBean> taskList = new ArrayList<TaskBean>();
taskList.add(new TaskBean("Task1", "K-CY-329", "144", "G-3", "1", "Pending", "XYZ"));
taskList.add(new TaskBean("Task2", "K-CY-356", "165", "A-10", "4", "Closed", "ABC"));
taskList.add(new TaskBean("Task3", "K-CY-343", "768", "B-12", "3", "Pending", "IJK"));
taskList.add(new TaskBean("Task4", "K-CY-786", "918", "F-9", "2", "Open", "PQR"));
TaskBeanList tsklst = new TaskBeanList("1", "5", "20", taskList);
return tsklst;
}
客户端JQGrid JS代码
jQuery(document).ready(function(){
jQuery("#list3").jqGrid({
autowidth: true,
datatype : "json",
url: "http://localhost:8080/SpringMVC/page4.htm",
mtype: 'get',
colNames : ["Title","Order ID","Realty","Building",
"Priority","Action","Assignee"],
colModel : [
{label: "Title", name: "title", index: "Title", jsonmap: "orderId"},
{label: "OrderID", name: "orderId", index: "OrderID", jsonmap: "orderId"},
{label: "Realty", name: "realty", index: "Realty", jsonmap: "realty" },
{label: "Building",name: "building",index: "Building",jsonmap: "building"},
{label: "Priority",name: "priority",index: "Priority",jsonmap: "priority"},
{label: "Action", name: "action", index: "Action", jsonmap: "action" },
{label: "Assignee",name: "assignee",index: "Assignee",jsonmap: "assignee"}
],
sortname : "Title",
sortorder : "desc",
shrinkToFit: true,
viewrecords: true,
jsonReader : {
root: "rows",
page: "page",
total: "total",
records: "records",
repeatitems: false,
cell: "cell",
id: "id",
userdata: "userdata",
subgrid: {root:"rows",
repeatitems: true,
cell:"cell"
}
}
}); });
任何人都可以帮忙解决这个问题吗?当我看到jqgrid示例代码时,看起来很简单,但我没有看到任何输出。输出页面为空。请帮助解决。
谢谢
我建议你先看看下面的教程:
在http://krams915.blogspot.com/2010/12/jqgrid-and-spring-3-mvc-integration.html上的jqGrid和Spring 3 MVC集成教程
您可以从该教程中找到答案,或者至少它会改进您正在寻找的内容。
@ user669789首先通过克里斯提到过的krams教程。我也是jqgrid的新手,但是教程和源代码对我帮助很大。另一种选择是根据jqgrid中的jsonreader使用硬编码的json值,看看是否itz得到人口。看看this example by Oleg
尝试将其写入printwriter,并通过URL调用天气来获取json输出
在Controller中,您可以尝试将列表转换为Json。如果所有列名都匹配,则Json值将直接绑定到JQGrid
控制器类
@RequestMapping("/page4.htm")
public @ResponseBody String getJQGridData(HttpServletRequest request, HttpServletResponse response) {
System.out.println("xml data");
List<TaskBean> taskList = new ArrayList<TaskBean>();
taskList.add(new TaskBean("Task1", "K-CY-329", "144", "G-3", "1", "Pending", "XYZ"));
taskList.add(new TaskBean("Task2", "K-CY-356", "165", "A-10", "4", "Closed", "ABC"));
taskList.add(new TaskBean("Task3", "K-CY-343", "768", "B-12", "3", "Pending", "IJK"));
taskList.add(new TaskBean("Task4", "K-CY-786", "918", "F-9", "2", "Open", "PQR"));
TaskBeanList tsklst = new TaskBeanList("1", "5", "20", taskList);
Gson gson = new GsonBuilder().setPrettyPrinting().create();
String result = gson.toJson(tsklst );
return result;
}
下载gson.jar,然后试试这个
它对我有用。您也可以从这里参考示例项目
http://www.jriyazahamed.blogspot.com/
以上是关于带有spring mvc的jqgrid json数据类型的主要内容,如果未能解决你的问题,请参考以下文章