Spring : URL 中的花括号是什么意思
Spring : What is the meaning of curly bracket in URL
我在控制器中有以下方法,我必须在其中上传图片但是我不知道为什么找不到我的请求,谁能告诉我如何在[=中传递userId
19=]?为什么在这里使用大括号?以及使用大括号时如何传递参数?
我这样发送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");
}
}
您正在请求 url 中的参数 file
正确的 URL 应该是 http://localhost:8555/api/uploadAcceptanceLetter/1?file=something
或者尝试在文件参数上添加 required=false 并检查请求是否成功
我在控制器中有以下方法,我必须在其中上传图片但是我不知道为什么找不到我的请求,谁能告诉我如何在[=中传递userId
19=]?为什么在这里使用大括号?以及使用大括号时如何传递参数?
我这样发送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");
}
}
您正在请求 url 中的参数 file 正确的 URL 应该是 http://localhost:8555/api/uploadAcceptanceLetter/1?file=something 或者尝试在文件参数上添加 required=false 并检查请求是否成功