求教如何将后台的json数据传送到前台easyUI中的datagrid中

如题所述

控制器和jsp:

@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>

温馨提示:答案为网友推荐,仅供参考