求教如何将后台的json数据传送到前台easyUI中的datagrid中 20
1个回答
展开全部
控制器和jsp:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
@RequestMapping(produces="text/plain;charset=UTF-8",value="datagridToJson")
@ResponseBody
public String datagridToJson(HttpServletRequest req) throws JsonGenerationException, JsonMappingException, IOException{
ObjectMapper objectMapper = new ObjectMapper();
Map map=new HashMap<>();
Book book=new Book(1, "剪掉你的dingding", "大叔");
Book book1=new Book(2, "洗掉你的dingding", "大姐");
List<Book> list=new ArrayList<Book>();
list.add(book);
list.add(book1);
map.put("rows",list);
map.put("total",2);
return objectMapper.writeValueAsString(map);
}
<table class="easyui-datagrid" id="tab1" title="Basic DataGrid" style="width:700px;height:250px"
data-options="singleSelect:true,collapsible:true,url:'${pageContext.request.contextPath}/easyui/datagridToJson',method:'get'">
<thead>
<tr>
<th data-options="field:'id',width:100">BOOk的ID</th>
<th data-options="field:'author',width:80,align:'right'">BOOk作者</th>
<th data-options="field:'name',width:80,align:'right'">BOOk名字</th>
</tr>
</thead>
</table>
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
@RequestMapping(produces="text/plain;charset=UTF-8",value="datagridToJson")
@ResponseBody
public String datagridToJson(HttpServletRequest req) throws JsonGenerationException, JsonMappingException, IOException{
ObjectMapper objectMapper = new ObjectMapper();
Map map=new HashMap<>();
Book book=new Book(1, "剪掉你的dingding", "大叔");
Book book1=new Book(2, "洗掉你的dingding", "大姐");
List<Book> list=new ArrayList<Book>();
list.add(book);
list.add(book1);
map.put("rows",list);
map.put("total",2);
return objectMapper.writeValueAsString(map);
}
<table class="easyui-datagrid" id="tab1" title="Basic DataGrid" style="width:700px;height:250px"
data-options="singleSelect:true,collapsible:true,url:'${pageContext.request.contextPath}/easyui/datagridToJson',method:'get'">
<thead>
<tr>
<th data-options="field:'id',width:100">BOOk的ID</th>
<th data-options="field:'author',width:80,align:'right'">BOOk作者</th>
<th data-options="field:'name',width:80,align:'right'">BOOk名字</th>
</tr>
</thead>
</table>
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询