Android Afianl框架(2)——FinalDB
如果你用过Hibernate,或Spring,那么对这个就很好理解了,首先上点代码
1.entity
/** * * @ClassName: User * @Author roy * @Date 2013-4-8 pm 04:40:49 * @Desc: TODO */ @Table(name="User_Table") public class User { @Id(column="id") private int id; private int age; private String name; private String department; public int getAge() { return age; } public void setAge(int age) { this.age = age; } public String getName() { return name; } public void setName(String name) { this.name = name; } public String getDepartment() { return department; } public void setDepartment(String department) { this.department = department; } public void setId(int id) { this.id = id; } public int getId() { return id; } }
2.实现类
/** * * @ClassName: P02_DBAct * @Author roy * @Date 2013-4-9 am 11:20:15 * @Desc: TODO */ public class P02_DBAct extends FinalActivity { @ViewInject(id=R.id.p02_db_data_id) TextView textView; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.p02_db_layout); FinalDb finalDb = FinalDb.create(this); User user = new User(); user.setAge(11); user.setName("wanghb"); user.setDepartment("SoftDepartment"); finalDb.save(user); List<User> userList = finalDb.findAll(User.class); //finalDb. Log.i("P02_DBAct", "User message" + userList == null ? "kong" : userList.get(0).getName()); textView.setText("User message:" + userList == null ? "kong" : userList.get(0).getName()); } }
这里要说到的是finalDb的用法
1.save
2.findAll
3.findAll(clazz, orderBy);//orderBy--用表里的一个字段名称即User对象里面的属性就行了,不用再加什么order by id desc 什么的
4.findAllByWhere(clazz, strWhere)
5.findAllByWhere(clazz, strWhere, orderBy)
6.findDbModelBySQL(strSQL)
7.findById(id, clazz)
8.
注:current_date 是SQLite的关键字,请勿用其作为表的字段。