Coustom 객체를 사용한 조회
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 | db.collection("company") .get() .addOnCompleteListener(new OnCompleteListener<QuerySnapshot>() { @Override public void onComplete(@NonNull Task<QuerySnapshot> task) { if (task.isSuccessful()) { for (QueryDocumentSnapshot document : task.getResult()) { companyList.add(document.toObject(Company.class)); } } else { Log.w(TAG, "Error getting company documents.", task.getException()); } } }); |
1 2 | // 조회된 데이터 매핑 Company company = document.toObject(Company.class); |
Coustom 객체를 사용한 추가
1 2 3 4 5 6 7 8 9 10 11 12 13 14 | db.collection("company") .add(company) // 객체를 넣어준다. .addOnSuccessListener(new OnSuccessListener<DocumentReference>() { @Override public void onSuccess(DocumentReference documentReference) { finish(); } }) .addOnFailureListener(new OnFailureListener() { @Override public void onFailure(@NonNull Exception e) { Log.w(TAG, "Failure save"); } }); |