File tree 1 file changed +13
-4
lines changed
1 file changed +13
-4
lines changed Original file line number Diff line number Diff line change @@ -38,6 +38,8 @@ JPA 这部分内容上手很容易,但是涉及到的东西还是挺多的,
38
38
39
39
## 2.配置数据库连接信息和JPA配置
40
40
41
+ 由于使用的是 h2 内存数据库,所以你直接运行项目数据库就会自动创建好。
42
+
41
43
下面的配置中需要单独说一下 ` spring.jpa.hibernate.ddl-auto=create ` 这个配置选项。
42
44
43
45
这个属性常用的选项有四种:
@@ -50,15 +52,22 @@ JPA 这部分内容上手很容易,但是涉及到的东西还是挺多的,
50
52
但是,** 一定要不要在生产环境使用 ddl 自动生成表结构,一般推荐手写 SQL 语句配合 Flyway 来做这些事情。**
51
53
52
54
``` properties
53
- spring.datasource.url =jdbc:mysql://localhost:3306/springboot_jpa?useSSL =false&serverTimezone =CTT
55
+ # 数据库url地址
56
+ spring.datasource.url =jdbc:h2:mem:jpa-demo
54
57
spring.datasource.username =root
55
58
spring.datasource.password =123456
59
+ spring.datasource.platform =h2
60
+ spring.datasource.driverClassName =org.h2.Driver
61
+
62
+ spring.jpa.properties.hibernate.enable_lazy_load_no_trans =true
56
63
# 打印出 sql 语句
57
64
spring.jpa.show-sql =true
58
- spring.jpa.hibernate.ddl-auto =create
65
+ spring.jpa.hibernate.ddl-auto =update
59
66
spring.jpa.open-in-view =false
60
- # 创建的表的 ENGINE 为 InnoDB
61
- spring.jpa.properties.hibernate.dialect =org.hibernate.dialect.MySQL55Dialect
67
+ server.port =8080
68
+ # H2控制台
69
+ spring.h2.console.enabled =true
70
+
62
71
```
63
72
64
73
## 3.实体类
You can’t perform that action at this time.
0 commit comments