【发布时间】: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 -
createPOST 操作通常没有额外的路径组件;它只是POST /documents具有适当的内容。 (您还应该让 Spring 为您完成有用的工作,并使用@RequestBody Document document而不是传递裸字符串。) -
@Phil 谢谢这似乎有效,只是为了确认我收到此错误:请求处理失败;嵌套异常是 java.lang.Exception: java.lang.RuntimeException: error while fopping .. 这意味着我已经到达方法,刚才方法中出现错误?
标签: java postman restful-url