updateChildren中Pojo和HashMap的区别

时间:2018-06-05 09:10:50

标签: java android firebase firebase-realtime-database hashmap

说#34;如果我使用updateChildren函数在Firebase中保存一个值为null的POJO是正确的,那就是我在setValue"中使用相同POJO的东西。 。我不想删除任何东西。在这种情况下,我必须使用HashMap

代码

usrBuilder = new Users.Builder();
        usrBuilder.setUid(uid)
                .setFull_name(name.getText().toString())
                .setSex((rb_F.isChecked())?"F":"M")
                .setBirthDate(data_nascita.getText().toString())
                .setEmail(email.getText().toString())
                .setCity_live(citta.getText().toString());

usrUpdated = new Users(usrBuilder);
        firebaseUpdate.put("/Users/"+uid+"/", usrUpdated);

//POJO USERS
public Users(Builder builder){
        uid = builder.uid;
        email= builder.email;
        full_name= builder.full_name;
        sex = builder.sex;
        birth_date = builder.birth_date;
        city_live = builder.city_live;
        url_img_profile_large = builder.url_img_profile_large;
        url_img_profile_small = builder.url_img_profile_small;

    }

url_img_profile *已删除。

现在我理解我的问题因为它看到了空值。

Firebase-root
    |
    --- Users
         |
         --- uid
                |
                --- name: "name"
                |
                --- sex: "F" 
                |
                --- email: "email@ame.it"
                |
                --- birth_date: "Jun 1, 2018" 
                |
                --- city: "Campobasso"
                |
                --- url_photo_small: "urlStorage" 
                |
                --- url_photo_large: "urlStorage"

1 个答案:

答案 0 :(得分:0)

当您使用updateChildren()方法时,您将覆盖该特定位置的对象,并且当您使用Map方法时,您正在更新该特定位置存在的子项的值。所以请记住,您可以自动将键/值对映射到符合JavaBeans标准的POJO,或者您可以使用Firebase-root | --- items | --- itemIdOne | --- name: "ItemOne" 单独访问每个键/值对。

假设您的数据库结构如下所示:

removeValue()

删除记录的最简单方法是直接在引用上使用DatabaseReference rootRef = FirebaseDatabase.getInstance().getReference(); rootRef.child("items").child(itemIdOne).removeValue();

<input type="text" class="link hidden" value="Hello World 2" style="position: absolute; left: -1000px;">