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="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>