【问题标题】:Some endpoints in Spring Boot app not working when receiving request from Angular front end从 Angular 前端接收请求时,Spring Boot 应用程序中的某些端点无法正常工作
【发布时间】:2020-12-27 05:27:18
【问题描述】:

我有以下终点:

@PutMapping(path = "/like/{id}")
public void likeQuestion(@PathVariable("id") String id, @Valid @NotNull @RequestBody Student student) {
    logger.info(id, student);
    questionService.likeQuestion(id, student);
}

当我尝试从 Angular 前端发送请求时,这不起作用:

likeQuestion(id: string, student: Student) {
  console.log(id, student);
return this.http.put(
  environment.baseUrl + '/api/questions/like/' + id,
  student
);

}

控制台仍会注销idstudent,但是,端点不会被记录。

我在同一个文件中有另一个端点可以工作:

 @PutMapping(path = "/edit-comment/{id}")
public void editComment(@PathVariable("id") String id, @Valid @NotNull @RequestBody Comment comment) {
    logger.info("Editing comment");
    questionService.editComment(id, comment);
}

这里可能存在什么潜在问题?谢谢你。控制器的请求映射为@RequestMapping("api/questions"),与前端请求uri匹配,所以我不知道可能是什么问题。

我尝试在开发工具中检查网络选项卡,但找不到正在发出的任何请求...

【问题讨论】:

  • 接收到的http状态码是什么?
  • 它甚至没有显示在开发工具中,我该如何检查?
  • 后端有什么错误..?
  • 我什至看不到,前端没有调用端点...

标签: angular spring-boot


【解决方案1】:

可能学生 DTO 字段无效,@valid 或 @notNull 在控制器日志之前触发

【讨论】:

    【解决方案2】:

    对不起大家,对不起。调用http后忘记订阅了。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2019-05-02
      • 2021-09-13
      • 2020-05-07
      • 2018-08-11
      • 2018-08-19
      • 1970-01-01
      • 2019-05-28
      • 2016-12-18
      相关资源
      最近更新 更多