下面是我的Class.java文件的模板:
class : "AB"
member : []
部门将有如下所示的一系列部门:
email : yuna13.com, //from User.java
email : katy89.com,
...
所以我想构建的最终数组结构如下:
class : "AB",
member : [
email : yuna13.com,
email : katy89.com,
...
]
以下是我将动态元素添加到departments数组中的代码,但是它是错误:
public void addMember(String tenlop, String userEmail){
Lophoc lop = lophocCollectionAccess.findOne("{tenlop:#}",tenlop).as(Lophoc.class);
lop.member.add(userEmail);
lophocCollectionAccess.save(lop);
}
public LophocDAO() {
lophocCollectionAccess = DBAccessProvider.getInstance().getCollection("lophoc");
}
这就是模特。' Class.java' :
public class Lophoc {
public static final String find = null;
@MongoId
@MongoObjectId
private String lopId;
private String malop;
private String tenlop;
private String siso;
private String giangvien;
public List<User> member = new ArrayList<User>();
public Lophoc() {
member = new ArrayList<User>();
}
public Lophoc(String lopId,String malop,String tenlop,String siso,String giangvien,User owner){
this.lopId=lopId;
this.malop=malop;
this.tenlop=tenlop;
this.siso=siso;
this.giangvien=giangvien;
this.member.add(owner);
}
--getters and setters---
请帮助解决上述问题并将对象动态添加到阵列中? 非常感谢你。