Android 安卓房间实体,如何处理静态场?
我们是否需要在文件室中用Android 安卓房间实体,如何处理静态场?,android,android-room,Android,Android Room,我们是否需要在文件室中用@ignore注释静态字段 @Entity(tableName = "table_users") public class User { private static final String MY_CONSTANT = "whatever"; @PrimaryKey(autoGenerate = true) public int id; public String name; publi
@ignore
注释静态字段
@Entity(tableName = "table_users")
public class User {
private static final String MY_CONSTANT = "whatever";
@PrimaryKey(autoGenerate = true)
public int id;
public String name;
public int age;
}
我读了这本书,但没有发现任何关于这方面的东西
我们是否需要在房间中用@ignore注释静态字段
不,它们会自动被忽略
通过创建项目,然后检查为数据库生成的java(数据库类名后缀为_Impl),可以看到这一点。该表将在createAllTables
方法中定义
例如:-
@Entity(tableName = "user")
public class User {
private static final String MY_CONSTANT = "whatever";
@PrimaryKey
Long id;
String userName;
String userEmail;
String userPassword;
public User(){};
@Ignore
public User(String userName, String userEmail, String userPassword) {
this.userName = userName;
this.userEmail = userEmail;
this.userPassword = userPassword;
}
}
结果:-
_db.execSQL("CREATE TABLE IF NOT EXISTS `user` (`id` INTEGER, `userName` TEXT, `userEmail` TEXT, `userPassword` TEXT, PRIMARY KEY(`id`))");
i、 e.没有“我的常数”列。太棒了,谢谢。