application.properties 配置:
spring.datasource.type=com.alibaba.druid.pool.DruidDataSource spring.datasource.driver-class-name=com.mysql.jdbc.Driver spring.datasource.url=jdbc:mysql://localhost:3306/meeting?useUnicode=true&characterEncoding=UTF-8&autoReconnect=true spring.datasource.username=root spring.datasource.password=123456 #JPA spring.jpa.hibernate.naming.physical-strategy = org.hibernate.boot.model.naming.PhysicalNamingStrategyStandardImpl spring.jpa.hibernate.ddl-auto=none spring.jpa.database=MYSQL spring.jpa.show-sql=true #根据实体生成表打开 #加载hibernate时根据实体类model创建数据库表,这是表名的依据是@Entity注解的值或者@Table注解的值, #spring.jpa.hibernate.ddl-auto= update
其中spring.jpa.hibernate.ddl-auto的属性有以下几种参数:
create:每次加载hibernate会自动创建表,以后启动会覆盖之前的表,所以这个值基本不用,严重会导致的数据的丢失。
create-drop : 每次加载hibernate时根据model类生成表,但是sessionFactory一关闭,表就自动删除,下一次启动会重新创建。
update:加载hibernate时根据实体类model创建数据库表,这是表名的依据是@Entity注解的值或者@Table注解的值,sessionFactory关闭表不会删除,且下一次启动会根据实体model更新结构或者有新的实体类会创建新的表。
validate:启动时验证表的结构,不会创建表
none:启动时不做任何操作
实体类:
生成的数据库表:
生成的varchar类型长度都255 可实体设置 或者个人改