In the code below, class Address
is nested in Entity User
. I wonder if all the attributes of Address
are private
, do we need getter
and setter
for each of the field in Address
? Notice there is a List<String>
, so I'm not sure if Room
will work well with @TypeConverter
in this case.
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;
}
You can easily add getter/setters with @Ignore
annotation and the converter will ignore these methods.
@Ignore
public List<String> getCity() {
return city;
}
你可以参考这里创建实体
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.