📅  最后修改于: 2022-03-11 14:52:24.194000             🧑  作者: Mango
myRef.orderByChild("name").equalTo("abc").runTransaction(new Transaction.Handler() {
@Override
public Transaction.Result doTransaction(MutableData mutableData) {
Student s = mutableData.getValue(Student.class);
if (s == null) {
return Transaction.success(mutableData);
}
s.setAge(20);
// Set value and report transaction success
mutableData.setValue(s);
return Transaction.success(mutableData);
}
@Override
public void onComplete(DatabaseError databaseError, boolean b,
DataSnapshot dataSnapshot) {
// Transaction completed
Log.d(TAG, "postTransaction:onComplete:" + databaseError);
}
});