【问题标题】:JQGRID in spring mvc and hibernatespring mvc和hibernate中的JQGRID
【发布时间】:2015-08-28 02:38:15
【问题描述】:

如何使用 spring 和 hibernate 在 jqGrid 中显示 oracle 10g 表中的数据? 表中有一些数据,我想在 jsp 中的可编辑 jqGrid 表中显示它们。谁能指导我怎么做。

protected ModelAndView onSubmit(HttpServletRequest request,
        HttpServletResponse response, Object command, BindException errors)
                throws Exception {
    rel_details reldetails = (rel_details) command;
    List l=reldetailsdao.save_release_details(reldetails);

    JSONObject responseDetailsJson = new JSONObject();
    JSONArray jsonArray = new JSONArray();

    Iterator itr=l.iterator();
    rel_details asd=null;
    while(itr.hasNext()){
        asd=(rel_details)itr.next();

        JSONObject formDetailsJson = new JSONObject();
        formDetailsJson.put("rel_id", asd.getRel_id());
        formDetailsJson.put("rel_name", asd.getRel_name());
        formDetailsJson.put("rel_modified_date", asd.getRel_modified_date());
        formDetailsJson.put("rel_desc", asd.getRel_desc());
        formDetailsJson.put("rel_env", asd.getRel_env());
        formDetailsJson.put("rel_change_req_no", asd.getRel_change_req_no());
        formDetailsJson.put("rel_status", asd.getRel_status());
        jsonArray.add(formDetailsJson);
    }

    responseDetailsJson.put("l", jsonArray);
    System.out.println(responseDetailsJson);

    return new ModelAndView("add_release","rel",responseDetailsJson);

【问题讨论】:

  • 在控制器内部,我能够获取数据并存储为 json 。我从link 下载了 jqgrid 的代码。但我不知道如何将该数据放入该网格中
  • 你需要把相关代码贴在这里
  • 我贴在控制器上方
  • 控制器看起来不错,您遇到了什么问题?
  • 问题是我从控制器 responseDetailsJson 传递的 json 无法使用 jquery 放入 jqgrid 或可编辑数据网格中

标签: spring hibernate jqgrid jqgrid-formatter


【解决方案1】:

如果您的技术堆栈是 Java 和 Spring,您必须通过以下步骤在 jqgrid 中显示您的结果。

  1. 创建一个类ResponseDTO,该类将包含您希望在 jqgrid 中显示的结果和其他值。
  2. 修改上面的onSubmit方法,返回你刚才在步骤1中创建的响应DTO。不需要使用JSONObjectJSONArray 上课。
  3. onSubmit 方法映射到一个 url,并确保该方法是 MVC 中控制器的一部分。
  4. 然后创建一个 JSP,它将引用上面的 url 如下所示以显示和编辑结果。

        $(document).ready(function(){
            $("#list").jqGrid({
                    datatype: 'json',
                    mtype: 'GET',
                    height: 'auto',
                    url:'actual url that retrieves results i.e., url created in step 3',
                    editurl:'actual url through which you want to edit the data',
                    colNames:['Col Name1','Col Name2','Col Name3'],
                    colModel:[]
                    ..................
                    ..................
              })
           })
    
  5. 您必须在类路径中包含 Jackson jar(例如 jackson-all-x.x.x.jar)才能进行必要的 JSON 转换。因此,您必须使用 @RequestBody@ResponseBody 注释。

希望这可以帮助您继续前进。如果您有任何问题,可以在此处参考link

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2012-04-13
    • 1970-01-01
    • 1970-01-01
    • 2012-02-01
    • 2018-08-02
    • 1970-01-01
    • 2017-01-03
    相关资源
    最近更新 更多