【发布时间】:2017-05-17 05:14:20
【问题描述】:
我在控制器中有以下方法,我必须在其中上传图片但我不知道为什么找不到我的请求,谁能告诉我如何在 URL 中传递userId?为什么在这里使用大括号?以及使用大括号时如何传递参数?
我正在发送这样的 URL http://localhost:8555/api/uploadAcceptanceLetter/1 但它给了我 404 的错误
@RequestMapping(method = RequestMethod.POST, value = "/uploadAcceptanceLetter/{userId}", produces="application/json")
public @ResponseBody AcceptanceLetter uploadAcceptanceLetter(Authentication authentication, @PathVariable("userId") Long userId,@RequestParam("file") MultipartFile file) {
if (!file.isEmpty()) {
return photoService.uploadAcceptanceLetter(file , userId);
} else {
throw new RuntimeException( "You failed to upload " + file.getOriginalFilename() + " because the file was empty");
}
}
【问题讨论】:
-
您如何提交此请求?显示您的 html/jquery 方面。你的方法定义为POST方法,所以需要表单提交或者ajax POST
标签: spring url parameters upload photo