首页 > 解决方案 > 使用 http.get 请求传递正文

问题描述

我在 Angular IO 中有一个应用程序,它是 Java 服务的客户端。我有一个搜索,我想通过许多搜索条件。然后我为此创建了一个对象。

export class CriteriosPesquisa{
    public opcaoSelecionada: string;
    public diaDe: Date;
    public diaAte: Date;
    public numNfe: string;
}

当我进行搜索时,我将对象传递到我的申请 Get 的正文中。(我将在一个网格中显示结果)显然我的问题是因为我将 body 与 GET 一起使用。

public getNfes(criterios: CriteriosPesquisa): Observable<Array<Nfe>>{
    const myHeaders = new Headers();
    myHeaders.append('Content-Type', 'application/json');
    // const myParams = new URLSearchParams();
    // myParams.append('criterios', criterios);
    const options = new RequestOptions({ headers: myHeaders, /*search: myParams,*/ body: JSON.stringify(criterios) });

    return this._http.request(`${URL_API}nfes`, options)
      .map(response => {
        return response.json();
      });
  }

2018-05-12 23:34:19.740 WARN 1076 --- [nio-8080-exec-6] .wsmsDefaultHandlerExceptionResolver:无法读取 HTTP 消息:org.springframework.http.converter.HttpMessageNotReadableException:缺少所需的请求正文:公共java.util.List br.com.minhasCompras.service.NfeService.buscarNfe(br.com.minhasCompras.eo.Criterios)

@RequestMapping(value = "/nfes")
public List<Nfe> buscarNfe(@RequestBody Criterios criterios){

    System.out.println(criterios.getOpcaoSelecionada());
    System.out.println(criterios.getNumNfe());
    System.out.println(criterios.getDiaAte());
    System.out.println(criterios.getDiaDe());

    return new ArrayList<Nfe>();
}

你知道吗?如何使用 GET 为我的客户传递对象?

标签: javaangularspring-boot

解决方案


推荐阅读