在下面的代码中,类Address
嵌套在实体User
中。我想知道Address
的所有属性是否都是private
,getter
中的每个字段是否都需要setter
和Address
?请注意,这里有一个List<String>
,所以我不确定Room
在这种情况下是否可以与@TypeConverter
一起使用。
public class Address {
public String street;
public String state;
public List<String> city;
@ColumnInfo(name = "post_code")
public int postCode;
}
@Entity
public class User {
@PrimaryKey
public int id;
public String firstName;
@Embedded
public Address address;
}
答案 0 :(得分:0)
您可以使用 @Ignore
注释轻松添加 getter/setter,转换器将忽略这些方法。
@Ignore
public List<String> getCity() {
return city;
}
答案 1 :(得分:-1)
您可以在这里参考 Create the entity