jquery+spring mvc带文件提交

xiaoxiao2021-02-27  196

1、前端需要jquery.js和jquery.form.js

                            var options={                                     type:"post",                                     url : '${ctx}/org/ajaxAdd',                                   async: false,                                     enctype:"multipart/form-data",                                     dataType : 'json',                                   success : function(obj, status) {                                         if(obj.resCode == '000000'){                                             showAlert("添加成功");                                         }else{                                             showAlert("添加失败");                                         }                                    },                                    error : function(obj, status, e) {                                          showAlert("请求失败");                                    }                             };                                                         $('form').ajaxSubmit(options); 

2、spring mvc Controller方法中参数增加   @RequestParam MultipartFile uploadImage(多个文件用数组接收),其他提交的属性可从request获取或用其他对方封装接收

@RequestMapping(value = "/org/ajaxEdit", method = RequestMethod.POST)     @ResponseBody     public void ajaxEdit(@RequestParam MultipartFile uploadImage,             HttpServletRequest request, HttpServletResponse response,             TOrganization tOrganization) throws Exception { }

转载请注明原文地址: https://www.6miu.com/read-12100.html

最新回复(0)