帐户实体
public class Account
{
@MongoObjectId
private String _id;
private String name;
public String get_id() {
return _id;
}
public void set_id(String _id) {
this._id = _id;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
}
public class JongoExample {<br>
MongoClient mongoClient = new MongoClient(); // code to connect with database
DB db = mongoClient.getDB("kommboxj");
Jongo jongo = new Jongo(db);<br>
MongoCollection accountCollection = jongo.getCollection("account");
Account account = new Account();<br>
account.setName("rks");<br>
String accountIdMongo = (String) accountCollection.insert(account).getUpsertedId();}
在这里我发现acountIdMongo为null,不知道如何获取它,这里我想插入帐户ObjectId。
答案 0 :(得分:-1)
对我来说这有帮助:
基于上述内容, Color.java 中的_id将为:
label.error {
font: 0/0 a;
}
然后在插入方法中的 PersistenceHandler.java 中,返回的对象将包含填充了_id的Mongo集合中的插入对象。
@MongoObjectId
private String _id;