我试图为Room创建一个dataclass,该类还有一个字段,仅用于视图。我不想把数据保存到房间里。
@Entity(tableName = "MyTable")
@Parcelize
data class MyTable(
@SerializedName("id") @PrimaryKey val id: String,
@SerializedName("field1") val field1: String?,
var selected: Boolean? = false //todo use @Ignore
) : Parcelable
以上代码有效。然而每当我尝试使用
@Ignore
带变量的注释
selected
变量这给了我以下的错误
error: Entities and Pojos must have a usable public constructor. You can have an empty constructor or a constructor whose parameters match the fields (by name and type).
如果我从构造函数中移除变量
@Entity(tableName = "MyTable")
@Parcelize
data class MyTable(
@SerializedName("id") @PrimaryKey val id: String,
@SerializedName("field1") val field1: String?
) : Parcelable{
var selected: Boolean? = false //todo use @Ignore
}
田野
挑选出来的
不会被写进包裹里。我怎样才能在不创建列的情况下将变量保留在类中,并将其保留在包中?
谢谢