把数据从控制器使用最短code有史以来jsp页面? [英] Put data from controller to jsp page using shortest code ever?

查看:147
本文介绍了把数据从控制器使用最短code有史以来jsp页面?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

需要code的改进感谢

need code improvement thanks

负荷电流的方式/显示数据页是:

Current way of loading/displaying data to page is:

$.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

控制器code是:

controller code is:

@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;
    }

由于必须在按一下按钮

thanks must be on button click

推荐答案

这个怎么样:

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

这篇关于把数据从控制器使用最短code有史以来jsp页面?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆