Spring MVC easyui1.3.2 datagrid无法加载数据

 jsp
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@include file="/common/page/jqueryMaster.jsp"%>

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
  <head>

    <script type="text/javascript" src="<%=root%>/info/js/infoList.js"  charset="utf-8"></script>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">

    <title>信息列表</title>
  </head>

  <body>
    <!-- 列表 -->
    <table id="tt">
    </table>

    <!-- 工具拦 -->
    <div id="tb" style="padding: 3px">
        <form method="post" action="" id="myForm" name="myForm">
            <br> 
            <span>信息标题:</span> <input id="ensurname" name="ensurname" style="width:160px; border: 1px solid #ccc">
            <span>创建人:</span> <input id="engivename" name="engivename" style="width:160px; border: 1px solid #ccc">
            <span>创建时间:</span> <input name="asampletbl.birthday" id="abirthday" class="easyui-datebox" currentText='今天' closeText='关闭' formatter="formatDate">
            <a href="#" class="easyui-linkbutton" iconAlign="right" data-options="iconCls:'icon-search'" onclick="doSearch()">查询</a>
            <a href="#" class="easyui-linkbutton" iconAlign="right" data-options="iconCls:'icon-undo'" onclick="Javascript:$('#tb').form('clear')">清空</a>
            <!-- 
            <a href="#" class="easyui-linkbutton" iconAlign="right" data-options="iconCls:'icon-remove'" onclick="dodelete()">删除</a>

            <a href="#" class="easyui-linkbutton" iconAlign="right" data-options="iconCls:'icon-add'" onclick="doadd()">添加</a>
             -->
            <a href="#" class="easyui-linkbutton" iconAlign="right" data-options="iconCls:'icon-add'" onclick="window.parent.addTab('tabId_infoCreate','信息新增','<%=root%>/createInfo.do')">添加</a>
            <!-- 
            <a href="#" class="easyui-linkbutton" iconAlign="right" data-options="iconCls:'icon-edit'" onclick="doedit()">修改</a>
             -->
        </form>
    </div>


  </body>
</html>

js

$(function() {
        console.info($("#tt").parent().width() - 2);
        $('#tt').datagrid({
            url : root + "/getInfoList.do",
            title : '信息列表',//文字提示
            iconCls : 'icon-ok',
            fitColumns : true,
            width : $("#tt").parent().width() - 2,//长度
            height : 20,//高度
            pageSize : 10,//默认每页多少行
            pageList : [ 10, 20, 30, 40, 50 ],//可以选择每页多少行
            collapsible:true,
            nowrap : false,
            striped : true,
            collapsible : true,
            loadMsg : '数据装载中......',//等待页面的时候,显示的内容
            toolbar : "#tb",//工具栏               调用ID为tb的div,将工具栏嵌套进去
            frozenColumns : [ [ {
                field : 'ck',
                checkbox : true
            } ] ],
            columns:[[{field:'id',title:'主键',width:30,hidden:true},
                      {field:'title',title:'信息标题',width:30, align:'center'},
                      {field:'operater',title:'发送人',width:30, align:'center'},
                      {field:'opertime',title:'发送时间',width:30, align:'center'}
            ]],
            pagination : true,//启动分页效果
            rownumbers : true, // 显示行数
            singleSelect: true // 只选择一行

        });

});

Controller
/**
     * 查询发送信息列表
     * 
     * @param request
     * @param model
     * @return
     * @throws Exception 
     */
    @RequestMapping(value="/getInfoList.do")
    @ResponseBody
    public Map<String, Object> getInfoList(int page,int rows) throws Exception {

        log.info("查询发送信息开始");

        int start = (page-1)*rows;

        List<Info> users = infoAccessService.getAll(start,rows);

        int total = infoAccessService.getNumber();

        Map<String, Object> map = new HashMap<String, Object>();

        map.put("total", total);
        map.put("rows", users);

        log.info("查询发送信息结束");
        return map;
    }


    以上是我的代码,在返回结果时总是无法加载

下一个断点调试下,看看是数据没有查询到,还是json返回错误还是你的easyui配置问题。

第一,我没见你前台的页面在哪儿放了datagrid控件


第二,datagrid控件加载数据时,需要json数据格式,你返回的是一个map,这是加载不了的。
可以考虑使用net.sf.json组件对你的map进行json格式转换。
map.put("total", total);
map.put("rows", users);

JSONObject jsonObj = JSONObject.fromObject(map);
return jsonObj;

对于jsonOBJ,在Action中进行定义。
@Results({
@Result(name = "jsonobj", type = "json", params = { "root", "jsonObj" }) })

具体关于net.sf.json的用法,可以网上搜一下,当然你也可以用别的组件,或者自己转换成json格式。

数据肯定传到前台了。因为能显示多少条数据,但是就是不显示内容。