Android 我需要getter、setter和额外的实体构造函数吗?
我试图在Android项目中使用ORMLite实现数据库持久化。从例子来看,一切都很好。一旦我开始使用它,我发现我并不完全理解它的要求和行为 假设我有一个名为Bone的类,我想继续使用它Android 我需要getter、setter和额外的实体构造函数吗?,android,ormlite,Android,Ormlite,我试图在Android项目中使用ORMLite实现数据库持久化。从例子来看,一切都很好。一旦我开始使用它,我发现我并不完全理解它的要求和行为 假设我有一个名为Bone的类,我想继续使用它 @DatabaseTable(tableName = "bones") public class Bone{ // user defined @DatabaseField(dataType = DataType.STRING) private String color; @DatabaseField priva
@DatabaseTable(tableName = "bones")
public class Bone{
// user defined
@DatabaseField(dataType = DataType.STRING)
private String color;
@DatabaseField
private double length;
@DatabaseField
private int quantity;
// db assigned
@DatabaseField(generatedId = true)
private int id;
public Bone(){
}
// constructors
public Bone(String color, int quantity) {
this(color, quantity, 0);
}
public Bone(String color, int quantity, int id) {
this.color = color;
this.quantity = quantity;
this.id = id;
}
public Bone(Bone old, int id){
this.color = old.color;
this.length = old.length;
this.quantity = old.quantity;
this.id = id;
}
public String getColor() {
return color;
}
public double getLength() {
return length;
}
public int getQuantity() {
return quantity;
}
public void setLength(double length) {
this.length = length;
}
public int getId() {
return id;
}
}
不需要。您只需要一个可访问的无参数构造函数,ORMLite就可以在反射工作之前实例化对象。有没有办法将getter/setter用于外部集合?您可以问这个问题并提供有关用户列表@deviant的更多详细信息吗?默认情况下,这是每个实体@kml\u ff的公共无参数构造函数。当您添加另一个构造函数时,问题就出现了。这时您需要专门添加一个无参数构造函数,所以从一开始就这样做并将其标记为ORM所需的构造函数总是一个好主意。谢谢。但我关于ormlite的主要问题是@Gray,我等待您的回复,等待链接的问题。。