【问题标题】:Postman :"status": 404, "error": "Not Found", "message": "Not Found",邮递员:“状态”:404,“错误”:“未找到”,“消息”:“未找到”,
【发布时间】:2020-08-05 02:33:05
【问题描述】:
@RestController()
@RequestMapping("/v1/e")
public class EC {
    @PostMapping(path = "{document}", consumes = "application/json", produces = "application/json")
    public ResponseEntity<InputStreamResource> createDocument(@PathVariable Dtype document,@RequestBody String data){
        //code
    }

我正在尝试向邮递员发出发帖请求,下面是我用来发帖的 URL

http://localhost:8080/v1/e?document=E_PC

但是,我在邮递员上收到以下错误

{
    "timestamp": "2020-08-05T02:22:03.008+0000",
    "status": 404,
    "error": "Not Found",
    "message": "Not Found",
    "path": "/v1/e"
}

【问题讨论】:

  • 您已将{document} 作为路径的一部分,而不是查询参数。试试POST /v1/e/E_PC
  • create POST 操作通常没有额外的路径组件;它只是 POST /documents 具有适当的内容。 (您还应该让 Spring 为您完成有用的工作,并使用 @RequestBody Document document 而不是传递裸字符串。)
  • @Phil 谢谢这似乎有效,只是为了确认我收到此错误:请求处理失败;嵌套异常是 java.lang.Exception: java.lang.RuntimeException: error while fopping .. 这意味着我已经到达方法,刚才方法中出现错误?

标签: java postman restful-url


【解决方案1】:

你也可以像下面这样使用:

@RestController
@RequestMapping("/v1/e")
public class EC {

  @PostMapping
  public ResponseEntity<?> createDocument(@RequestParam("document") String document){
      //code
  }

}

而你的POST REQUESThttp://localhost:8080/v1/e?document=E_PC

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2021-09-19
    • 2021-05-12
    • 1970-01-01
    • 2021-10-13
    • 1970-01-01
    • 2022-01-14
    • 2020-03-20
    相关资源
    最近更新 更多