0

Below is the template of my Class.java file:

class     : "AB"       
member    : []

where departments will have array of departments like below:

email : yuna13.com,     //from User.java
email : katy89.com,
...

so the final array structure i want to construct is as below:

class     : "AB",
member    : [
        email : yuna13.com,     
        email : katy89.com,
        ...
        ]

Below is the code where i am adding the elements to an departments array dynamically,...but it is errors:

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");
}

And this is Models.'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---

Please help to above problem and Dynamically add objects into array? Thank you very much.

0 Answers0