嗨,我正试图从数据库中删除文章。我在postman中测试了我的java函数,但是没有。
我的组件.html
<div class="card" *ngFor="let car of article" style="width: 18rem;margin-right: 30px;">
<div class="card-header bg-transparent">
<div class="btn-group" role="group" aria-label="Basic example" *ngIf="car.idOwner !== -1" >
<button type="button" class="btn btn-link"><i class="fas fa-pencil-alt"></i> Edit</button>
<button type="button" class="btn btn-link"><i class="fas fa-trash-alt" (click)="removeArticle(car.idArticle)"></i> Supprimer</button>
我的组件.ts:
removeArticle(idArticle: number) {
if(idArticle === undefined) {
this.displayMessage("An error has occured while removing the article", 2);
return;
}
if (confirm("Do you really want to delete this article?")) {
this.articleServices.deleteArticle(idArticle)
.pipe()
.subscribe(data => {
this.findAllArticles();
this.displayMessage("article succfully removed", 1);
});
}
}
我的服务
deleteArticle(idArticle: number) {
return this.http.delete<Article>(AppSettings.APP_URL + "/articles/" + idArticle);
}
删除.java:
@DeleteMapping("/{idArticle}")
public ResponseEntity deleteArticle(@PathVariable(name = "idArticle") Long idArticle) {
if (idArticle == null) {
return ResponseEntity.badRequest().body("Cannot remove article with null ID");
}
Article article = articleRepository.getOne(idArticle);
if (article == null) {
return ResponseEntity.notFound().build();
}
articleRepository.delete(article);
return ResponseEntity.ok("article removed with success");
}
我得到以下错误:
error httperrorresponse{标题:httpheaders,状态:200,状态文本:“确定”,url:“http://localhost:8080/courses/articles/2“,确定:false,…}错误:{错误:syntaxerror:在xmlhtt的json.parse()处的位置0处的json中出现意外标记a…,文本:“article removed with success”}标题:httpheaders{normalizednames:map(0),lazyupdate:null,懒虫:ƒ} 消息:“http解析失败http://localhost:8080/courses/articles/2“name:”httperrorresponse“确定:错误状态:200 statustext:”确定“url:”http://localhost:8080/课程/文章/2“原型:httpresponsebase构造函数:ƒ httperrorresponse(init)proto:对象
我需要帮助。提前谢谢!
暂无答案!
目前还没有任何答案,快来回答吧!