java - 使用 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 为我的客户传递对象?
解决方案
推荐阅读
- javascript - Javascript 输入 UTC 字符串
- python - 由于命名空间为空,Python XPath lxml 无法读取 SVG 路径元素?
- c - 浮点函数总是返回 0.000000
- laravel - Laravel 分页在第一页后不起作用
- python-3.x - 关于使用 pydrive 列出所有文件
- java - Spring bean 销毁上的 System.exit() 是否有效?
- c++ - 代码块自动缩进突然停止工作(Windows 10)
- r - 使用 lapply 标准化 ts() 函数
- firebase - 使用 Firebase 无法登录的 Google Play 游戏
- matlab - 在Matlab中用二分法求解方程