java - WebClient 将数据保存到 Mongo
问题描述
我使用 WebClient 从外部 api 检索了一些关于客户端的数据。现在我想将它保存到 MongoDb,但正在努力解决它。这里我是如何检索数据的:
public class Main {
public static void main(String[] args) throws URISyntaxException, MalformedURLException {
WebClient client = WebClient.create();
RequestDTO requestBody = new RequestDTO("getClients", new RequestDataDto("1", "60"));
ProductWrapperMars response = client.post()
.uri(new URI("MyURL"))
.header("token", "MyToken") //I have a header as well
.contentType(MediaType.APPLICATION_JSON)
.accept(MediaType.APPLICATION_JSON)
.bodyValue(requestBody)
.retrieve()
.bodyToMono(ClientList.class)
.block();
}
}
下面是 Client 类的样子:
public class ClientList {
private Boolean available;
private List<Clients> data;
}
public class Clients {
@Id
private Long id;
private String name;
private Timestamp date;
//getters and setters
}
我应该如何组织将检索到的数据保存到 Mongo?
解决方案
推荐阅读
- visual-studio-2008 - VS 2008 SP1 无法在 MC9200 上部署 Windows CE 7.0
- wordpress - 有没有办法添加自定义 onclick 图标
- php - 在 Symfony3 的多对多关系表中“检查是否存在”的最佳方法是什么?
- sql - 根据每条记录的多列查找重复项
- java - 无法使用 Jexcel API 读取单元格值
- r - 比较 lme 中的 beta 系数
- macos - 在 Mac 上自动重命名下载的文件
- c# - 如何下载 Excel 文件
- python-3.x - 为什么代码在 CodingBat Make_Brick 问题中不起作用,但在 Jupyter 笔记本中起作用?
- jsf - 为什么使用 Primefaces 的 JSF 中的 Intellij 代码自动完成功能不起作用?