Angular请求不要在后端(Spring Boot)中映射我的API

我有一个错误,我不知道为什么,但是在春季启动时角度不激活我的api,并且我没有发现错误。

这是代码。

服务(英语)

setPost(postId:number):Observable<boolean>{
    return this.http.post<boolean>(this.myAppUrl+this.myApiPostUrl+postId+'/setPost',this.authService.getLoggedUserFromSessionStorage())
      .pipe(
        retry(1),catchError(this.errorHandler)
      );
  }

组件(角度)

isAlreadyOpen(){
    this.postService.isOpen(this.postId).subscribe( isAuth => {
      if(isAuth) {
        this.cantModify();
      } else {
        console.log('im here');
        this.postService.setPost(this.postId);
        this.router.navigate(['/post/edit/',this.postId]);
      }
  });
  }

在其他代码中输入该代码不会出现问题,因为chrome控制台会在“ im here”(我在这里)打印。

CONTROLLER(JAVA)

@RequestMapping(value = "/posts/{id}/setPost",method = RequestMethod.POST)
    public ResponseEntity<Boolean> setPost(@PathVariable("id") int idPost,@RequestBody UserDTO userCorrente) {
        PostUser postUser = postUserService.set(idPost,userCorrente);
        if (postUser != null) {
            return new ResponseEntity<>(true,HttpStatus.OK);
        } else {
            return new ResponseEntity<>(false,HttpStatus.INTERNAL_SERVER_ERROR);
        }
    }

角度 this.postService.isOpen(此api,效果很好)

不工作this.postService.setPost,我试图删除所有内容以查看是否有地图

isAlreadyOpen(){
        this.postService.setPost(this.postId);
        this.router.navigate(['/post/edit/',this.postId]);
      }
  }

但是什么也没有,不起作用,我没有在Chrome的DEV TOOLS(网络)中看到该请求,并且在Spring Console中也没有看到任何东西。

cosmos_macrocosm 回答:Angular请求不要在后端(Spring Boot)中映射我的API

您需要在subscribe()上致电this.postService.setPost(this.postId),否则将不会触发该请求。

本文链接:https://www.f2er.com/3138103.html

大家都在问