我用的是springmvc我想把Controller中的List传到前台去怎么传? 前台怎么获取到list的值?

@RequestMapping(value="/address")publicStringfindaddress(){ReceivedGoodsAddressreceiv... @RequestMapping(value="/address")
public String findaddress(){
ReceivedGoodsAddress receivedgoodsaddress=new ReceivedGoodsAddress();
List<ReceivedGoodsAddress> list = addressService.findReceivedGoodsAddress(receivedgoodsaddress);
return “jsp路径”
}
展开
 我来答
chenvvxin
推荐于2017-10-05 · 超过32用户采纳过TA的回答
知道答主
回答量:81
采纳率:0%
帮助的人:47.2万
展开全部

用@ResponseBody

    @RequestMapping(value = "/address", method = RequestMethod.POST)
    @ResponseBody
    public Map<String, Object> addressPOST() {
        Map<String, Object> map = new HashMap<>();
        ReceivedGoodsAddress receivedgoodsaddress=new ReceivedGoodsAddress();
        List<ReceivedGoodsAddress> list = addressService.findReceivedGoodsAddress(receivedgoodsaddress);
        map.clear();
        map.put("list", list);
        return map;
    }
    //前台用jquery+ajax
    $.ajax({
                type:'POST',
                url:'${contextPath}/address',
                dataType:'json',
                success:function(data){
                        $.each(data.list,function(i,item){
                            alert(i);
                            alert(item.id);
                            alert(item.name);
                        });
                }
            });
推荐律师服务: 若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询

为你推荐:

下载百度知道APP,抢鲜体验
使用百度知道APP,立即抢鲜体验。你的手机镜头里或许有别人想知道的答案。
扫描二维码下载
×

类别

我们会通过消息、邮箱等方式尽快将举报结果通知您。

说明

0/200

提交
取消

辅 助

模 式