InsertClassIdforFirebase復元

This commit is contained in:
ろむねこ 2024-07-03 15:44:46 +09:00
parent 9536b0d9c2
commit 8b72a68026
No known key found for this signature in database
GPG Key ID: FA1F39A1BA37D168

View File

@ -0,0 +1,19 @@
package com.example.oplogy;
import com.google.firebase.firestore.FirebaseFirestore;
import java.util.HashMap;
import java.util.Map;
public class InsertClassIdforFirebase {
public void insertClassId(int classId) {
FirebaseFirestore db = FirebaseFirestore.getInstance();
Map<String, Object> data = new HashMap<>();
data.put("classId", classId); // classId is inserted as a number
db.collection("classId_Database").add(data)
.addOnSuccessListener(documentReference -> System.out.println("DocumentSnapshot added with ID: " + documentReference.getId()))
.addOnFailureListener(e -> System.err.println("Error adding document: " + e));
}
}