英文:
Angular 8 delete method is not calling spring boot delete method
问题
我的 Angular 8 删除方法没有调用 Spring Boot 的删除方法(日志中没有打印任何内容)。
Angular 8 删除方法:
deleteStudent(id: number): Observable<any> {
console.log(`${this.baseUrl}/deleteById/${id}`);
return this.httpClient.delete(`${this.baseUrl}/deleteById/${id}`, { responseType: 'text' });
}
Spring Boot 删除方法(REST API):
@DeleteMapping("/deleteById/{id}")
@ResponseBody
ResponseEntity<?> deleteById(@PathVariable("id") long id){
try{
studentService.deleteById(id);
LOGGER.info("记录成功删除");
return new ResponseEntity<>(HttpStatus.OK);
}catch (Exception e){
return new ResponseEntity<>(HttpStatus.INTERNAL_SERVER_ERROR);
}
}
在控制台打印 Angular 的 URL,例如:http://localhost:8888/deleteById/55,我将其复制并在 Postman 中使用,特定记录被成功删除。这个问题只出现在删除方法中,其他方法都正常工作。
英文:
My angular 8 delete method is not calling spring boot delete method (nothing prints in log)
angular 8 delete method :
deleteStudent(id: number): Observable<any> {
console.log(`${this.baseUrl}/deleteById/${id}`);
return this.httpClient.delete(`${this.baseUrl}/deleteById/${id}`, { responseType: 'text' });
}
spring boot delete method (REST API) :
@DeleteMapping("/deleteById/{id}")
@ResponseBody
ResponseEntity<?> deleteById(@PathVariable("id") long id){
try{
studentService.deleteById(id);
LOGGER.info("record successfully deleted");
return new ResponseEntity<>(HttpStatus.OK);
}catch (Exception e){
return new ResponseEntity<>(HttpStatus.INTERNAL_SERVER_ERROR);
}
}
after printing the angular url eg: http://localhost:8888/deleteById/55 in console I copied it and used in postman, the particular record deleted successfully. This problem only occurs for delete method, another methods are perfectly work.
答案1
得分: 0
这是我的错误,我没有在服务类中订阅删除方法。
英文:
It was my mistake I haven't subscribe to the delete method in service class.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论