[英]'delete' not supported spring boot
使用 Angular 8 和 Springboot 应用程序...通过 JSON 传递值获取错误:此处不支持请求删除是错误:
此应用程序没有明确的 /error 映射,因此您将其视为后备。
Thu Dec 05 22:55:04 WET 2019 出现意外错误(type=Method Not Allowed,status=405)。 不支持请求方法“GET”
@DeleteMapping("/Emp/{id}")
public boolean deleteEmployee(@PathVariable Long id) {
collaborateurRepository.deleteById(id);
return true;
}
组件.ts
deleteEmployee() {
this.employeservice.deleteEmployee(this.employee.id)
.subscribe(data => console.log(data), error => console.log(error));
this.gotoList();
}
服务 :
deleteEmployee( id: number): Observable<Object> {
return this.http.delete(`http://localhost:8080/api/Emp/`+id);
}
看起来您正在调用 REST-Api 来删除带有 HTTP-GET 请求的条目。 您必须使用 HTTP-DELETE 调用此端点,这将防止 Method not allowed 错误。 假设您的 UI 有一个类似get(/Emp/123)
的调用,它应该是delete(/Emp/123)
。
我找到了答案,除了删除方法之外,我还必须添加 Get 方法谢谢你们:)
@RequestMapping(value="/empdelete/{id}", method= {RequestMethod.DELETE, RequestMethod.GET})
public boolean deleteEmployee( @PathVariable("id") Long id) {
collaborateurRepository.deleteById(id);
return true;
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.