Spring:URL中的花括号是什么意思

时间:2017-05-17 05:14:21

标签: spring url parameters upload photo

我在控制器中有以下方法,我必须上传图片但是我不知道为什么找不到我的请求,有人能告诉我如何在网址中传递userId吗?为什么花括号在这里使用?以及如何在使用花括号时传递参数?

我正在发送这样的网址 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");
            }                               
    }

1 个答案:

答案 0 :(得分:1)

您在网址中请求参数文件 正确的网址应该是http://localhost:8555/api/uploadAcceptanceLetter/1?file=something 或者尝试在文件参数上放置 required = false 并检查请求是否成功

相关问题