/**
* @Entity
public class Student {
@Id(autoincrement = true)//设置id,并自增长
private Long id;
@Unique//唯一约束
@NotNull//不能为空
@Property(nameInDb = "sname")
private String name;
private String gender;
private int age;
private String address;
*/
DaoSession daoSession = DaoMaster.newDevSession(this, StudentDao.TABLENAME);
//2、获取对应的Dao对象
studentDao = daoSession.getStudentDao();
//3、调用增删改查的方法
studentDao.insert(student);//增
studentDao.update(student);//改
studentDao.delete(student);/dao.deleteByKey(Long.valueOf(post+1));//删
studentDao.loadAll();//查询所有
//条件查询
//1、先获取QueryBulder对象
QueryBuilder<Student> builder = studentDao.queryBuilder();
//单个条件查询 gt > lt < ge >= le<= eq == like 模糊查询
builder.where(StudentDao.Properties.Id.gt(6)).build().list();
//and条件查询 多条件&查询
WhereCondition condition = builder.and(StudentDao.Properties.Id.gt(6), StudentDao.Properties.Address.eq("河北"));
builder.where(condition).build().list();//多条件查询
//or条件查询 多条件|查询
WhereCondition conditionOr = builder.or(StudentDao.Properties.Id.gt(6), StudentDao.Properties.Address.eq("河北"));
builder.where(conditionOr).build().list();//多条件或查询
* @Entity
public class Student {
@Id(autoincrement = true)//设置id,并自增长
private Long id;
@Unique//唯一约束
@NotNull//不能为空
@Property(nameInDb = "sname")
private String name;
private String gender;
private int age;
private String address;
*/
DaoSession daoSession = DaoMaster.newDevSession(this, StudentDao.TABLENAME);
//2、获取对应的Dao对象
studentDao = daoSession.getStudentDao();
//3、调用增删改查的方法
studentDao.insert(student);//增
studentDao.update(student);//改
studentDao.delete(student);/dao.deleteByKey(Long.valueOf(post+1));//删
studentDao.loadAll();//查询所有
//条件查询
//1、先获取QueryBulder对象
QueryBuilder<Student> builder = studentDao.queryBuilder();
//单个条件查询 gt > lt < ge >= le<= eq == like 模糊查询
builder.where(StudentDao.Properties.Id.gt(6)).build().list();
//and条件查询 多条件&查询
WhereCondition condition = builder.and(StudentDao.Properties.Id.gt(6), StudentDao.Properties.Address.eq("河北"));
builder.where(condition).build().list();//多条件查询
//or条件查询 多条件|查询
WhereCondition conditionOr = builder.or(StudentDao.Properties.Id.gt(6), StudentDao.Properties.Address.eq("河北"));
builder.where(conditionOr).build().list();//多条件或查询