【发布时间】:2017-04-19 09:25:49
【问题描述】:
我正在使用 spring jdbc 和 mongoDB。我将有如下文件。 一个像
{
"_id" : ObjectId("58f49f05c88c8f2cb8061e12"),
"temp" : {
"27" : {
"59" : "5"
},
"28":{
"0":"0",
"1":"1"
}
},
"luminosity" : {
"27" : {
"59" : "3"
}
},
"identifier" : 753
}
另一个可能像
{
"_id" : ObjectId("58f49f05c88c8f2cb8061e12"),
"humidity" : {
"27" : {
"59" : "5"
}
},
"identifier" : 753
}
那么我该如何为此编写一个映射类。请帮忙! 我写过类似的东西
@Document(collection = "Data")
public class Data {
private String identifier;
/**
* @return the identifier
*/
public String getIdentifier() {
return identifier;
}
/**
* @param identifier
* the identifierto set
*/
public void setIdentifier(String identifier) {
this.identifier= identifier;
}
}
如何为其他字段编写映射器?这是动态的
【问题讨论】:
-
你的数据结构很奇怪。为什么会有一个名为“27”的物体,它代表什么?如果您无法更改数据模型,您可以将其加载为 json 对象或linkedtreemaps。
-
只是想知道下面的答案是否有帮助?
-
@p.streef 数字代表分钟/秒。谢谢你的回复
-
感谢@notionquest 的回复。它是部分使用完整的。部分是因为正如我提到的温度和光度不是固定的。可能我必须处理数据模型本身
标签: mongodb dynamic field spring-jdbc