【问题标题】:Angular 8 delete method is not calling spring boot delete methodAngular 8删除方法没有调用spring boot删除方法
【发布时间】: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


【解决方案1】:

我没有订阅服务类中的删除方法是我的错误。

【讨论】:

    猜你喜欢
    • 2017-12-14
    • 2013-06-09
    • 2019-04-29
    • 2022-12-09
    • 2012-04-08
    • 2019-01-30
    • 2013-11-15
    • 2021-12-13
    • 1970-01-01
    相关资源
    最近更新 更多