假设我有一个pojo
public class example{
private String id;
private String photoId
}
现在当保存这个 pojo 的一个实例时,id 被保存为 objectId。我还希望 photoId 将被序列化为 ObjectId。是否有某种注释可以添加到 photoId 以启用它?
public class example{
@Id
private String id; //default objectId serialization
@MongoType(ObjectId.class) //not real annotation, looking for real one
private String photoId; // enforce ObjectId serialization - what i want
mongoTemplate.insert(examplePojo); //will result as {_id :objectId(), photoId: objectId(...)}
----- EDIT ------ photoId 是 objectId 的字符串代表,例如:
public void saveExample(String id, String photoId){
Example example = new Example(id, photoId);
mongoTemplate.insert(example);
}
谢谢你的帮助!
罗伊