eweb4j-1.9-支持ActiveRecord模式
@Entity@Table(name="t_pet")public class Pet extends Model{ public final static Pet instance = new Pet(); private String name; private int age; public Pet(){} public Pet(String name, int age){ this.name = name; this.age = age; } //setter and getter}//使用new Pet("xiaohei", 5).create();//insertnew Pet("xiaohei", 5).save();//当没有ID值的时候是insertPet pet = new Pet("xiaobai",4);pet.create();//insert这时候pet.id已经被注入了pet.setName("test");pet.save();//这时候因为pet.id有值,所以是updatepet = new Pet();pet.setId(2);pet.load();//通过id值去查询数据库,并将数据注入到pet实例中。List<Pet> pets = Pet.instance.findAll();/* 分页 */List<Pet> page = Pet.instance.find().fetch(10);page = Pet.instance.find().fetch(2, 5);/* 条件查询 */List<Pet> pets = Pet.instance.find("byName", "xiaohei").fetch();pets = Pet.instance.find("byNameAndAge", "xiaohei", 5).fietch();pets = Pet.instance.find("name = ?", "xiaohei").fetch();Pet p = Pet.instance.find("name = ?", "xiaohei").first();p = Pet.instance.findById(3);p = Pet.instance.find("byNameAndAge", "xiaohei", 5).first();/* 删除 */Pet.instance.delete("byName", "xiaohei");Pet.instance.deleteAll();/* 计算 */long rows = Pet.instance.count();/* select count(*) */rows = Pet.instance.count("byName", "xiaohei");/* count(*) ... where name='xoapjeo' */Pet.instance.dao().selectAll().query();Pet.instance.dao().select("name","age").where().field("id").equal(5).query(1, 5);Pet.instance.dao().insert("name","age").values("test", 4).execute();Pet.instance.dao().update().set(new String[]{"name","age"}, "test", 8).execute();Pet.instance.dao().delete().execute();Pet.instance.dao().xxxxxxx......