gpt4 book ai didi

javascript - Spring Boot不支持“删除”

转载 作者:行者123 更新时间:2023-12-02 22:21:48 24 4
gpt4 key购买 nike

使用 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;
}

组件.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 调用此端点,这将防止出现“方法不允许”错误。假设您的 UI 有一个类似 get(/Emp/123) 的调用,它应该是 delete(/Emp/123)

关于javascript - Spring Boot不支持“删除”,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59204522/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com