@RequestMapping("datagrid") public void datagrid(Model model, @ModelAttribute BeanName bean, HttpServletRequest request, HttpServletResponse response) { bean.setOffset(bean.getRows() * (bean.getPage()-1) );//limit:start DataGrid dataGrid = new DataGrid(); dataGrid.setRows(service.selectList(bean));//list dataGrid.setTotal(service.selectListCount(bean));//list total count writeJson(response, dataGrid);//对象转换成json输出 } public class DataGrid { private Long total = 0L; private List rows = new ArrayList(); //setter... //getter... } /** * 将对象转换成JSON字符串,并响应回前台 * * @param object * @throws IOException */ public void writeJson(HttpServletResponse response,Object object) { try { String json = com.alibaba.fastjson.JSON.toJSONStringWithDateFormat(object, "yyyy-MM-dd HH:mm:ss"); response.setContentType("text/html;charset=utf-8"); response.getWriter().write(json); response.getWriter().flush(); } catch (IOException e) { log.debug(e.getMessage()); } } //sql: select * from table_ where 1=1 order by ${sort} ${order} limit ${offset},${rows} /***js**/ $(function(){ dg2 = $('#dg2').datagrid({ url : '/datagrid.action', //iconCls : 'icon-save', pagination : true, pagePosition : 'bottom', rownumbers : true, pageSize : 1, pageList : [ 20, 50, 100], fit : true, fitColumns : true, nowrap : true, border : true, idField : '', sortName : 'f.name', sortOrder : 'asc', singleSelect : true, columns : [ [ {field:'id',title:'详情',align:'center',30, formatter:function(value,row,index){ return '<a href="#" onclick="openInfo(' + row.id + ')">详情</a>'; } }, {field:'xbr.real_name',title:'姓名',align:'center',sortable:true,50, formatter:function(value,row,index){ if(row.bean != null) return row.bean.realName; } } ] ], onDblClickRow: function(rowIndex, row){ } }); }); <body> <table id="dg2" title="我的列表" ></table> </body>