'delete' 不支持 spring 启动
'delete' not supported spring boot
使用 Angular 8 和 Springboot 应用程序...通过 JSON 传递值时出现错误:
不支持请求删除
这是错误:
This application has no explicit mapping for /error, so you are seeing
this as a fallback.
Thu Dec 05 22:55:04 WET 2019 There was an unexpected error
(type=Method Not Allowed, status=405). Request method 'GET' not
supported
@DeleteMapping("/Emp/{id}")
public boolean deleteEmployee(@PathVariable Long id) {
collaborateurRepository.deleteById(id);
return true;
}
Component.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)
.
我找到了答案,除了删除方法之外,我还必须添加获取方法
谢谢你们:)
@RequestMapping(value="/empdelete/{id}", method= {RequestMethod.DELETE, RequestMethod.GET})
public boolean deleteEmployee( @PathVariable("id") Long id) {
collaborateurRepository.deleteById(id);
return true;
}
使用 Angular 8 和 Springboot 应用程序...通过 JSON 传递值时出现错误: 不支持请求删除 这是错误:
This application has no explicit mapping for /error, so you are seeing this as a fallback.
Thu Dec 05 22:55:04 WET 2019 There was an unexpected error (type=Method Not Allowed, status=405). Request method 'GET' not supported
@DeleteMapping("/Emp/{id}")
public boolean deleteEmployee(@PathVariable Long id) {
collaborateurRepository.deleteById(id);
return true;
}
Component.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)
.
我找到了答案,除了删除方法之外,我还必须添加获取方法 谢谢你们:)
@RequestMapping(value="/empdelete/{id}", method= {RequestMethod.DELETE, RequestMethod.GET})
public boolean deleteEmployee( @PathVariable("id") Long id) {
collaborateurRepository.deleteById(id);
return true;
}