【问题标题】:Spring : What is the meaning of curly bracket in URLSpring:URL中的大括号是什么意思
【发布时间】: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


【解决方案1】:

您在 url 中请求一个参数 file 正确的 URL 应该类似于 http://localhost:8555/api/uploadAcceptanceLetter/1?file=something 或尝试在文件参数上加上 required=false 并检查请求是否成功

【讨论】:

  • 您使用什么程序来进行 POST 请求?你不会在浏览器中写 URL,对吧?
  • 我正在使用邮递员
  • 由于错误是 404 来自您的请求,您的应用程序上下文是 api 吗?
猜你喜欢
  • 2013-05-28
  • 2011-01-07
  • 2022-11-30
  • 2019-06-16
  • 1970-01-01
  • 2013-01-31
  • 1970-01-01
  • 1970-01-01
  • 2016-09-12
相关资源
最近更新 更多