首页 > easyui+springmvc数据返回问题

easyui+springmvc数据返回问题

前台代码

<table id="dg" title="My Users" class="easyui-datagrid" style="width:550px;height:250px"
        url="regist.do"
        toolbar="#toolbar"
        rownumbers="true" fitColumns="true" singleSelect="true">
    <thead>
        <tr>
            <th field="username" width="50">First Name</th>
            <th field="lastname" width="50">Last Name</th>
            <th field="phone" width="50">Phone</th>
            <th field="email" width="50">Email</th>
        </tr>
    </thead>

后台:

@RequestMapping(value = "regist", method = RequestMethod.POST)
    public Object regist(HttpServletRequest request, User user) throws Exception {
      List<User>  userList=    userService.getUsers();
      System.out.println(userList);
    Map<String, Object> result = new HashMap<String, Object>(2) ; 
      JSONArray arr = new JSONArray();
      JSONObject obj = new JSONObject();
      for(int i =0;i<userList.size();i++){
           obj.put("username", userList.get(i).getUsername());
           arr.add(obj);
      }
    result.put("total",userList.size() );
    result.put("rows", arr);
    return JSONObject.fromObject(result);
    }    

运行时可以跳到regist方法里,但是浏览器报 jquery-1.7.2.min.js:4 POST http://localhost:8080/SpringM... 404 (Not Found) ? 查询的数据咋加载到easyui表格里的?


easyui里的数据好像是直接写到响应输出流里。,需要加上@ResponseBody注解


服务端方法签名,改成get


方法前面加上@ResponseBody
返回变成return result;


easyui 没用过,不过按照用过的来看一般都是转成json 字符串来填充datasource 的

【热门文章】
【热门文章】