【发布时间】:2020-07-18 05:58:51
【问题描述】:
我的 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("record successfully deleted");
return new ResponseEntity<>(HttpStatus.OK);
}catch (Exception e){
return new ResponseEntity<>(HttpStatus.INTERNAL_SERVER_ERROR);
}
}
在控制台中打印 angular url 例如:http://localhost:8888/deleteById/55 后,我将其复制并在邮递员中使用,特定记录已成功删除。仅删除方法会出现此问题,其他方法可以正常工作。
【问题讨论】:
-
您是否检查了浏览器网络选项卡中的 XHR 请求/响应。响应状态是什么?
-
按下删除按钮后没有任何反应,这是为什么呢
-
其他方法是 200。
标签: java angular spring-boot rest http