如何从角度承诺中恢复身体?

发布于 2025-02-11 00:01:16 字数 1233 浏览 0 评论 0原文

如何从从角承诺中获得的反应中恢复身体。以下是输出。我想要第三个身体的数据,我不确定该如何重新计算。同样,我不确定为什么我会得到嵌套的诺言。请指教。

下面的代码:

  fetch = () => {   
    debugger;   
    let url  = `${environment.api}${Paths.FetchData}`+this.userId;
    let req: HttpRequest<any> = new HttpRequest("Get", url, {
        headers: new HttpHeaders({
            "Accept": "text/html",
            "Content-Type": "text/html"
        }),
        responseType: "json"
    });    
    this.http.request(req).toPromise().then(r => {
      debugger;
      console.log(r);
       return r;
      });
} 

后端代码:

@RequestMapping(value = "/fetchData/{userId}", method = RequestMethod.GET)
public String fetchData(@PathVariable("userId") String userId) {
    System.out.println("calling00");
    if (!MyUtility.checkNullOrZero(Long.valueOf(userId))) {
        try {
            return service.fetchData(Long.valueOf(userId));
        } catch (Exception e) {
            log.error("Error ", e);
            return null;
        }
    }
    return null;
}

How to return the body from the response received from an angular promise. Below is the output. I want the data from the third body which i am not sure how can i retreive. Again i am not sure why i am getting nested body for a promise. Please advise.

enter image description here

Below code :

  fetch = () => {   
    debugger;   
    let url  = `${environment.api}${Paths.FetchData}`+this.userId;
    let req: HttpRequest<any> = new HttpRequest("Get", url, {
        headers: new HttpHeaders({
            "Accept": "text/html",
            "Content-Type": "text/html"
        }),
        responseType: "json"
    });    
    this.http.request(req).toPromise().then(r => {
      debugger;
      console.log(r);
       return r;
      });
} 

Backend Code :

@RequestMapping(value = "/fetchData/{userId}", method = RequestMethod.GET)
public String fetchData(@PathVariable("userId") String userId) {
    System.out.println("calling00");
    if (!MyUtility.checkNullOrZero(Long.valueOf(userId))) {
        try {
            return service.fetchData(Long.valueOf(userId));
        } catch (Exception e) {
            log.error("Error ", e);
            return null;
        }
    }
    return null;
}

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

烟凡古楼 2025-02-18 00:01:16
import { HttpClient } from '@angular/common/http';

constructor(private readonly http: HttpClient) { }

getRequest(){
   return this.http.get(reqUrl).toPromise()
}
import { HttpClient } from '@angular/common/http';

constructor(private readonly http: HttpClient) { }

getRequest(){
   return this.http.get(reqUrl).toPromise()
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文