Jongo --MongDB-ORM
Jongo 通过内部实现的JSON Mapper等可以实现BsonDocument和对象之间的转换。
Jongo 官网:http://jongo.org/
public class Demo01 {
@Ignore
public void test01() {
MongoClient mongo = new MongoClient("192.168.0.222", 27017);
DB db = mongo.getDB("test");
Jongo jungo = new Jongo(db);
MongoCollection catagories = jungo.getCollection("category");
Catagory catagory = new Catagory();
catagory.setCate("CBBB");
catagory.setExplain("EBBB");
catagory.setParent("PBBB");
Hobby hobby01 = new Hobby();
hobby01.setName("NBBB");
hobby01.setStfr("SBBB");
Hobby hobby02 = new Hobby();
hobby02.setName("2NBBB");
hobby02.setStfr("2SBBB");
catagory.setHobbies(ImmutableList.of(hobby01,hobby02));
catagories.save(catagory);
}
@Test
public void test02(){
MongoClient mongo = new MongoClient("192.168.0.222", 27017);
DB db = mongo.getDB("test");
Jongo jungo = new Jongo(db);
MongoCollection category = jungo.getCollection("category");
MongoCursor<Catagory> catagories = category.find().as(Catagory.class);
System.out.println("count:" + catagories.count());
while(catagories.hasNext()){
Catagory ca = catagories.next();
System.out.println(ca.toString());
}
}
}