How to add users into a class?

5 views
Skip to first unread message

Yuna

unread,
Jul 27, 2017, 2:29:16 AM7/27/17
to Jongo

I am doing: adding users into to a class...but it is errors....I repaired and more wrong.


I wrong at addUser()...I found Jongo but I don't understand about save() method...Please help me.

 public class LophocDAO{

        private MongoCollection lophocCollectionAccess;

        public LophocDAO() {
                lophocCollectionAccess = DBAccessProvider.getInstance().getCollection("lophoc");
            }

             public boolean isMember(String tenlop, String user){
                    MongoCursor<Lophoc> cursor = lophocCollectionAccess.find("{tenlop:#,member.email:#}",tenlop,user).as(Lophoc.class);
                    return cursor.count() > 0;
                }

            public User addMember(String tenlop, String user){

                    Lophoc lop = lophocCollectionAccess.save("{member.email:#}",user).as(Lophoc.class);         
                }

models.Lophoc.java

    public class Lophoc {

    @MongoId
    @MongoObjectId
    private String lopId;
    private String malop;
    private String tenlop;
    private String siso;
    private String giangvien;

    public List<User> members = new ArrayList<User>();

    public Lophoc(){
        members = new ArrayList<String>();
    }

    public Lophoc(String lopId,String malop,String tenlop,String siso,String giangvien){
        this.lopId=lopId;
        this.malop=malop;
        this.tenlop=tenlop;
        this.siso=siso;
        this.giangvien=giangvien;
        members = new ArrayList<String>();
    }
--getter and setter--
Reply all
Reply to author
Forward
0 new messages