求教如何将后台的json数据传送到前台easyUI
1个回答
展开全部
控制器和jsp:
1234567891011121314151617181920212223242526
@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>
1234567891011121314151617181920212223242526
@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>
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询