我怎样才能寄一封信 DELETE
请求 thymeleaf
? 我试了以下方法:
<form action="" th:method="delete">
<input type="submit" class="btn btn-primary" href="/person/123" value="Delete" />
</form>
@RequestMapping(value="/person/{id}", method = RequestMethod.DELETE)
@ResponseBody
public String delete(@PathVariable String id) {
personService.delete(id);
return "Successfully deleted";
}
但我得到的只是: org.springframework.web.HttpRequestMethodNotSupportedException: Request method 'POST' not supported
1条答案
按热度按时间5hcedyr01#
如果您使用的是springboot2.2+,那么需要明确地启用对此的支持。将以下内容添加到
application.properties
:springboot<2.2总是注册过滤器,对于springboot2.2或更高版本,您需要设置属性。
提示:可以更换
@RequestMapping(value="/person/{id}", method = RequestMethod.DELETE)
与@DeleteMapping("/person/{id}")