单例模式
static DbUtils db = null; public static DbUtils getDb(Context context) { if (context == null) { context = DoctorApplication.getInstance(); } if (db == null) { db = DbUtils.create(context, "xUtils.db"); }); db.configAllowTransaction(true); return db; } db.configAllowTransaction(true); return db; }
创建实体
@Table(name = "User")
public class User {
private int id; //主键ID,必须
private String uid;
private String type;
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
public String getType() {
return type;
}
public void setType(String type) {
this.type = type;
}
public String getUid() {
return uid;
}
public void setUid(String uid) {
this.uid = uid;
}
}
原文:http://www.cnblogs.com/jeno-song/p/5054844.html