有谁能告诉我如何从控制器获取数据,将类型为hashmap的数据返回到jqgrid?
这是我尝试过的。它进入了一个无限的lop
$(document).ready(function(){
$("#datatable").jqGrid({
url:"${pageContext.request.contextPath}/employees",
cache: false,
colNames:["id","name","age","salary","address","laptop"],
colModel:[
{name:"id",index:"id", width:60},
{name:"name",index:"name", width:90},
{name:"age",index:"age", width:100},
{name:"salary",index:"salary", width:80, align:"right"},
{name:"address",index:"address", width:80,
align:"right"},
{name:"laptop",index:"laptop", width:80,align:"right"}
],
mtype: "GET",
rownumbers: true,
rownumWidth: 40,
gridview: true,
caption: "Hashmap Data"
});
});
控制器部分
@RequestMapping(value="/employees", method = RequestMethod.GET)
public ModelAndView listEmployees() {
Map<String, Object> model = new HashMap<String, Object>();
model.put("employees",
prepareListofBean(employeeService.listEmployeess()));
for (Entry<String, Object> entry : model.entrySet()) {
String key = entry.getKey().toString();
Object value = entry.getValue();
System.out.println("hello key, " + key + " value " + value);
}
return new ModelAndView("employeesList", model);
}
例如: 员工价值[1 ram 22 12234 usa yes,6 abc 25 23889 xyz,yes]
请有人帮我解决这个问题。 它给出了解析错误:无效的xml消息
答案 0 :(得分:2)
也许你错过了jqgrid选项中的datatype
键
检查您的网址${pageContext.request.contextPath}/employees
返回的内容是什么?并在另一个选项datatype
根据documentation,datatype
的默认值为xml
。
尝试将其更改为json