【发布时间】:2018-08-05 12:34:05
【问题描述】:
我基于Service Components using this tutorial.创建了一个Spring Boot应用
我的删除请求是这样构造的:
@RequestMapping(value = "/api/greetings/{id}", method = RequestMethod.DELETE, consumes = MediaType.APPLICATION_JSON_VALUE)
public ResponseEntity<Greeting> deleteGreeting(@PathVariable("id") Long id, @RequestBody Greeting greeting) {
greetingService.delete(id);
return new ResponseEntity<Greeting>(HttpStatus.NO_CONTENT);
}
所有其他请求最终都可以正常工作,但是如果我在 Postman 中发出 DELETE 请求,则会收到以下错误:
{
"timestamp": 1519060345434,
"status": 415,
"error": "Unsupported Media Type",
"exception": "org.springframework.web.HttpMediaTypeNotSupportedException",
"message": "Content type 'application/x-www-form-urlencoded' not supported",
"path": "/api/greetings/2"
}
我检查了以下问题,没有任何帮助(难怪,它们都没有发出 DELETE 请求:
415 Unsupported MediaType for POST request in spring application
【问题讨论】:
-
您可以使用
@RestController,如果您制作一些api,并为您的删除功能使用@DeleteMapping注释。
标签: maven spring-boot request spring-data postman