本文整理匯總了Java中org.bson.types.ObjectId.toHexString方法的典型用法代碼示例。如果您正苦於以下問題:Java ObjectId.toHexString方法的具體用法?Java ObjectId.toHexString怎麽用?Java ObjectId.toHexString使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類org.bson.types.ObjectId
的用法示例。
在下文中一共展示了ObjectId.toHexString方法的4個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: clearAndPopulateDB
import org.bson.types.ObjectId; //導入方法依賴的package包/類
@Before
public void clearAndPopulateDB() throws IOException {
MongoClient mongoClient = new MongoClient();
MongoDatabase db = mongoClient.getDatabase("test");
MongoCollection<Document> userDocuments = db.getCollection("users");
userDocuments.drop();
List<Document> testUsers = new ArrayList<>();
testUsers.add(Document.parse("{\n" +
" name: \"Chris\",\n" +
" age: 25,\n" +
" company: \"UMM\",\n" +
" email: \"[email protected]\"\n" +
" }"));
testUsers.add(Document.parse("{\n" +
" name: \"Pat\",\n" +
" age: 37,\n" +
" company: \"IBM\",\n" +
" email: \"[email protected]\"\n" +
" }"));
testUsers.add(Document.parse("{\n" +
" name: \"Jamie\",\n" +
" age: 37,\n" +
" company: \"Frogs, Inc.\",\n" +
" email: \"[email protected]\"\n" +
" }"));
ObjectId samsId = new ObjectId();
BasicDBObject sam = new BasicDBObject("_id", samsId);
sam = sam.append("name", "Sam")
.append("age", 45)
.append("company", "Frogs, Inc.")
.append("email", "[email protected]");
samsIdString = samsId.toHexString();
userDocuments.insertMany(testUsers);
userDocuments.insertOne(Document.parse(sam.toJson()));
// It might be important to construct this _after_ the DB is set up
// in case there are bits in the constructor that care about the state
// of the database.
userController = new UserController("test");
}
開發者ID:UMM-CSci-3601-S17,項目名稱:digital-display-garden-iteration-2-spraguesanborn,代碼行數:41,代碼來源:UserControllerSpec.java
示例2: getObjectIdByRealType
import org.bson.types.ObjectId; //導入方法依賴的package包/類
public static Object getObjectIdByRealType(Class<?> fieldType, ObjectId objectId) {
if (fieldType == String.class || fieldType == StringObjectId.class) {
return objectId.toHexString();
} else if (fieldType == ObjectId.class) {
return objectId;
} else {
throw new BsonMapperConverterException("BsonValue ObjectId just can be converted to String or ObjectId.");
}
}
示例3: serialize
import org.bson.types.ObjectId; //導入方法依賴的package包/類
@Override
public JsonElement serialize(ObjectId objectId, Type type, JsonSerializationContext jsonSerializationContext) {
return new JsonPrimitive(objectId.toHexString());
}
示例4: clearAndPopulateDB
import org.bson.types.ObjectId; //導入方法依賴的package包/類
@Before
public void clearAndPopulateDB() throws IOException {
MongoClient mongoClient = new MongoClient();
MongoDatabase db = mongoClient.getDatabase("test");
MongoCollection<Document> flowerDocuments = db.getCollection("flowers");
flowerDocuments.drop();
List<Document> testFlowers = new ArrayList<>();
testFlowers.add(Document.parse("{\n" +
" _id: \"id-1\",\n" +
" commonName: \"tulip\",\n" +
" cultivar: \"cltv-tulip\",\n" +
" source: \"src-a\",\n" +
" gardenLocation: \"loc-1\",\n" +
" year: 2016\n" +
" }"));
testFlowers.add(Document.parse("{\n" +
" _id: \"id-2\",\n" +
" commonName: \"lily\",\n" +
" cultivar: \"cltv-lily\",\n" +
" source: \"src-a\",\n" +
" gardenLocation: \"loc-1\",\n" +
" year: 2016\n" +
" }"));
testFlowers.add(Document.parse("{\n" +
" _id: \"id-3\",\n" +
" commonName: \"daisy\",\n" +
" cultivar: \"cltv-daisy\",\n" +
" source: \"src-b\",\n" +
" gardenLocation: \"loc-2\",\n" +
" year: 2016\n" +
" }"));
ObjectId roseId = new ObjectId();
BasicDBObject rose = new BasicDBObject("_id", roseId);
rose = rose.append("commonName", "rose")
.append("cultivar", "cltv-rose")
.append("source", "src-b")
.append("gardenLocation", "loc-2")
.append("year", 2016);
roseIdString = roseId.toHexString();
flowerDocuments.insertMany(testFlowers);
flowerDocuments.insertOne(Document.parse(rose.toJson()));
// It might be important to construct this _after_ the DB is set up
// in case there are bits in the constructor that care about the state
// of the database.
flowerController = new FlowerController("test");
}
開發者ID:UMM-CSci-3601-S17,項目名稱:digital-display-garden-iteration-2-spraguesanborn,代碼行數:48,代碼來源:FlowerControllerSpec.java