Java 中的 Postman:“status”:404,“error”:“Not Found”,“message”:“Not Found”

问题描述 投票:0回答:2

我有一个使用 Postman 的 Java 程序。我正在尝试在 Postman 上发出发帖请求。我的代码:

@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
    }

以下是我用来发帖的网址:

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"
}
java postman restful-url
2个回答
0
投票

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

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

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

}

你的

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


0
投票

这会很好用:

@RestController()
@RequestMapping("/v1/e/{document}")
public class EC {
    @PostMapping
    public ResponseEntity<InputStreamResource> createDocument(@PathVariable Dtype document,@RequestBody String data) {
        //code
    }
© www.soinside.com 2019 - 2024. All rights reserved.