从Angular前端接收请求时,SpringBoot应用程序中的某些端点无法正常工作
我有以下终点:
@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
);
}
控制台仍会注销id并且student,但是不会记录端点。
我在同一个文件中有另一个端点可以工作:
@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 匹配,所以我不知道可能是什么问题。
我尝试检查开发工具中的网络选项卡,但找不到任何请求...
回答
也许 Student DTO 字段无效,并且 @valid 或 @notNull 在控制器日志之前触发
THE END
二维码