SpringMVC配置easyui-datagrid
SprimgMVC的UserController.java
@RequestMapping(value = "listUserForJson") @ResponseBody public Object listUserForJson(){ User user = new User(); List<User> users = userDao.listUser(user); Map<String,Object> jsonMap = new HashMap<String,Object>(); jsonMap.put("rows",users); jsonMap.put("total",users.size()); Object jsonObject = JSONObject.toJSON(jsonMap); System.out.println(jsonObject); return jsonObject; }
JSP页面配置easyui-datagrid
<body>
<table id="dataTable" class="easyui-datagrid" style="width:400px;height:250px">
<thead>
<tr>
<th data-options="field:'id'">ID</th>
<th data-options="field:'name'">名称</th>
<th data-options="field:'age'">价格</th>
</tr>
</thead>
</table>
<a href="/ssm">回到首页</a>
</body>
<script>
$(document).ready(function() {
page_init();
});
function page_init() {
$("#dataTable").datagrid({
url: "listUserForJson",
pagination: true,//分页控件
});
}
</script>
魔法师一枚,垃圾代码制造者,搬砖预备队十三大队,请多多赐教!
浙公网安备 33010602011771号