使用ORM的方式选择
- 先创建模型类,再迁移到数据库中
- 优点:简单快捷,定义一次模型类即可,不用写sql
- 缺点:不能尽善尽美的控制创建表的所有细节问题,表结构发生变化的时候,也会难免发生迁移错误
- 先用原生SQL创建数据库表,再编写模型类作映射
- 优点:可以很好的控制数据库表结构的任何细节,避免发生迁移错误
- 缺点:可能编写工作多(编写sql与模型类,似乎有些牵强)
- 先用原生sql语句创建了数据库 在模型类里面描写字段就可以不用那么详细 声明类型长度 默认值就行了
数据库表
数据库中以表为组织单位存储数据。
对应关系
类----------表
类中属性----------表中字段
对象----------记录