【问题标题】:How to create entity in Room DB with extend some other class with some fields如何在 Room DB 中创建实体,并使用某些字段扩展其他类
【发布时间】:2018-03-23 07:40:12
【问题描述】:

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

  • 用户信息
  • 用户数据

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

UserTable(超类)

@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;

}

用户信息(子类)

@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 中,但是存在重复值的问题,所以在这种情况下我们可以做什么。

【问题讨论】:

    标签: android sqlite android-room


    【解决方案1】:

    UserData 类中的字段为private。这意味着您不能在 UserInfo 类中访问它们。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2018-01-29
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2023-04-08
      • 1970-01-01
      • 2021-09-24
      相关资源
      最近更新 更多