搭个小项目,如何生成数据表呢?
我一般是直接设计实体类,然后用代码实现entity后,利用hibernate生成。
SpringBoot项目中基本步骤
1.项目中引入pring-boot-starter-data-jpa依赖;
2.配置yml或properties文件:
#指定数据库类型
spring.datasource.driver-class-name=com.mysql.jdbc.Driver
#指定数据库地址和编码方式
spring.datasource.url=jdbc\:mysql\://127.0.0.1\:3306/spring?useUnicode=true&characterEncoding=UTF-8
#数据库账号
spring.datasource.username=root
#数据库密码
spring.datasource.password=root
#hibernate的命名策略
spring.jpa.hibernate.naming.strategy=org.hibernate.cfg.ImprovedNamingStrategy
#自动创建|更新|验证数据库表结构
#create:每次加载hibernate时都会删除上一次的生成的表
#update:
#最常用的属性,第一次加载hibernate时根据model类会自动建立起表的结构(前提是先建立好数据库),
#以后加载hibernate时根据 model类自动更新表结构
spring.jpa.hibernate.ddl-auto=update
3.写好实体类后,运行项目就行了。
你应当热爱自由!
作者:Leejk,转载请注明原文链接:https://www.cnblogs.com/leejk/p/15474437.html