【问题标题】:Put data from controller to jsp page using shortest code ever?使用最短的代码将数据从控制器放到 jsp 页面?
【发布时间】:2015-10-11 17:36:39
【问题描述】:

需要代码改进谢谢

当前加载/显示数据到页面的方式是:

$.getJSON('${cp}/'+url+'/'+myCode, function(response){
            $.each(response, function(index, item){                         
                switch(index) {
                    case "code":
                        $("#code").val(item);
                        break;
                    case "name":
                        $("#name").val(item);
                        break;
                    case "street1":
                        $("#street1").val(item);
                        break;
                    case "street2":
                        $("#street2").val(item);
                        break;
                    case "postalCode":
                        $("#postalCode").val(item);
                        break;
            }
        });//end of each
    });//end of getJson

控制器代码是:

@RequestMapping(value="url/{myCode}", method=RequestMethod.GET)
    public @ResponseBody Supplier getSupplier(@PathVariable("myCode")
            Integer myCode, HttpSession session) {
        setTable();
        Supplier supp = srvSupplier.get(myCode);
        return supp;
    }

谢谢一定是点击按钮

【问题讨论】:

    标签: jquery ajax spring hibernate jsp


    【解决方案1】:

    这个怎么样:

    $.each(response, function( key, item ){                         
        $("#" + key).val(item);
    });
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-10-20
      • 1970-01-01
      • 2016-02-12
      • 2015-10-08
      相关资源
      最近更新 更多