前端js:
var submit_data = new FormData();var name = $("#name").val();let file = $("#file")[0].file[0];submit_data.append("file", file);submit_data.append("name", name);$.ajax({ url: "http://localhost:8080/caochanglu/getSearch/getRule", type: "POST", data: submit_data, async: false, dataType: "json", cache: false, processData: false, contentType: false, success: function(data) { console.log(data); }, error: function(err) { console.log(err); }});
后台spring
@ResponseBody@RequestMapping(value = "getRule", methon = {RequestMethod.GET, RequestMethod.POST})public String getRule(HttpServletRequest request, @RequestParam("file") MultipartFile file){ String name = request.getParameter("name");}