[英]Changing the field on the MongoDatabase of a pojo class?
I have a CSV file that I am reading into MongoDB using a POJO class like:我有一个 CSV 文件,我正在使用 POJO class 读入 MongoDB,例如:
public class Student {
@JsonProperty("NAME")
private String name;
@JsonProperty("ID")
private Integer id;
//getters and setters
}
I want the fields in Mongo DB to be appeared like:我希望 Mongo DB 中的字段显示如下:
{
"NAME": "John",
"ID": 4212
}
Instead they are like:相反,他们是这样的:
{
"name": "John",
"id": 4212
}
All of them are lower case, instead of upper case.它们都是小写的,而不是大写的。
If you are using Spring Data MongoDB, you can use @Field
to change the field name as follows:如果你使用的是Spring数据MongoDB,你可以使用@Field
更改字段名,如下:
public class Student {
@JsonProperty("NAME")
@Field("NAME")
private String name;
@JsonProperty("ID")
@Field("ID")
private Integer id;
//getters and setters
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.