时间:2021-07-01 10:21:17 帮助过:14人阅读
Codec类
package demo2; import org.bson.BsonReader; import org.bson.BsonWriter; import org.bson.codecs.Codec; import org.bson.codecs.DecoderContext; import org.bson.codecs.EncoderContext; public class Chaoba1Codec implements Codec<Chaoba1>{ @Override public void encode(BsonWriter writer, Chaoba1 value, EncoderContext encoderContext) { // TODO Auto-generated method stub writer.writeStartDocument(); writer.writeString("name", value.getName()); // writer.writeString("sex", value.getSex()); writer.writeEndDocument(); } @Override public Class<Chaoba1> getEncoderClass() { // TODO Auto-generated method stub return Chaoba1.class; } @Override public Chaoba1 decode(BsonReader reader, DecoderContext decoderContext) { // TODO Auto-generated method stub reader.readStartDocument(); Chaoba1 chaoba1=new Chaoba1(); chaoba1.set_id(reader.readObjectId("_id")); chaoba1.setName(reader.readString("name")); // chaoba1.setSex(reader.readString("sex")); reader.readEndDocument(); return chaoba1; } }
MongoDb二
标签:mongo nbsp 获取 string server with color setname 需要