gpt4 book ai didi

android - 如何在 Room DB 中创建实体并使用某些字段扩展其他类

转载 作者:太空狗 更新时间:2023-10-29 14:40:15 25 4
gpt4 key购买 nike

我在 Room DATABASE 中有两个实体,如下所示。

  • 用户信息
  • 用户数据

UserInfo 正在扩展 UserData,但我不想要 UserInfo 类中的所有字段。

UserTable(父类(super class))

@Entity
public class UserData {

@PrimaryKey
private int userId = 0;

private String prefix = null;
private String firstName = null;
private String middleName = null;
private String lastName = null;
private String email = null;

}

UserInfo(子类)

@Entity
public class UserInfo extends UserData {

int id;

//HERE all other fields are created from UserData and i don't want it into UserInfo Table..

}

注意:我必须在 UserInfo 类中使用 @Ignore 注释吗?我还想将整个类保存到 SharedPreference 中,但是存在重复值的问题,所以在这种情况下我们可以做什么。

最佳答案

UserData 类中的字段是私有(private)的。这意味着您不能在 UserInfo 类中访问它们。

关于android - 如何在 Room DB 中创建实体并使用某些字段扩展其他类,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49444614/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com