我想使用angularjs发送ImageFile(MultipartFile)servlet。 但是,它无法进入@RequestParam Annotation spring。
JSP
<form method="POST" id="image-form" enctype="multipart/form-data">
<input type="file" id="imageFile" name="imageFile" accept="image/jpg,image/jpeg,image/png" />
<div id="search-button">
<input type="button" ng-click="searchCtrl.imageSearch();">
</div>
</form>
的javascript
var $form;
var formData = new FormData();
$form = $("#image-form");
formData.append("imageFile", $form[0]);
request = $http({
method : 'post',
url : "/addImage",
data : data,
headers : {
'Content-Type' : undefined
},
transformRequest : null
});
return (request.then(handleSuccess, handleError));
的java
@RequestMapping(value = "/addImage", method = RequestMethod.POST)
@ResponseBody
public List<SearchImageRequestModel> logo_upload(HttpServletRequest request, HttpServletResponse response,
Model model, @PathVariable("service_id") String serviceId, @RequestParam(value = "imageFile") MultipartFile file)
throws ServletException, IOException {
...
您是否无法在@RequestParam注释中获取MultipartFile。 请劝告。