java - 从 Mongo 集合创建 Java POJO
问题描述
我有一个现有的 MongoDB,我需要为所有集合编写 Java POJO。
是否有任何工具可以从 mongo 集合中自动生成 POJO?
我能够找到将 Mongo 集合转换为 JSON 的工具,但找不到将集合转换为 Java POJO 的合适方法。
解决方案
使用http://www.jsonschema2pojo.org/
像这样的json:
{
"type":"object",
"working":true,
"id":1
}
会产生
-----------------------------------com.example.Example.java-----------------------------------
package com.example;
import com.google.gson.annotations.Expose;
import com.google.gson.annotations.SerializedName;
public class Example {
@SerializedName("type")
@Expose
private String type;
@SerializedName("working")
@Expose
private Boolean working;
@SerializedName("id")
@Expose
private Long id;
public String getType() {
return type;
}
public void setType(String type) {
this.type = type;
}
public Boolean getWorking() {
return working;
}
public void setWorking(Boolean working) {
this.working = working;
}
public Long getId() {
return id;
}
public void setId(Long id) {
this.id = id;
}
}
推荐阅读
- python - 如何获得最后 2 个轴的 argmax?
- java - 如何将实体收集为“地图
>”? - css - 如何在 v-col 内装上绝对的 v-overlay?
- visual-studio - 为什么这个 std::map 不能在 Visual C++ 的监视窗口中以可用的方式显示?
- django - DetailView Django 不工作错误页面未找到
- c# - 有没有其他正确的方法可以在 C# 表单中的两个不同选项卡上进行相同的控制?
- spring-boot - 带有原型 bean 的 Spring AOP
- reactjs - 如何在 React 的输入元素中突出显示主题标签?
- angular - Angular and Http Calls How to make an http call to keep trying until a success response is received?
- javascript - 在反应中访问'scrollLeft'属性