springmvc 多文件上传multipartfile 怎么获取前台传过来的参数

2024-11-16 00:21:47
推荐回答(2个)
回答1:

用@ResponseBody


   

    @RequestMapping(value = "/address", method = RequestMethod.POST)
    @ResponseBody
    public Map addressPOST() {
        Map map = new HashMap<>();
        ReceivedGoodsAddress receivedgoodsaddress=new ReceivedGoodsAddress();
        List 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);
                        });
                }
            });

回答2:

@RequestMapping("fileUpload")
public String fileUpload(@RequestParam("file") MultipartFile file) {
}