Skip to content

Commit a3a78c1

Browse files
committed
Update springboot-jpa.md
1 parent ccb5f01 commit a3a78c1

File tree

1 file changed

+13
-4
lines changed

1 file changed

+13
-4
lines changed

docs/basis/springboot-jpa.md

+13-4
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,8 @@ JPA 这部分内容上手很容易,但是涉及到的东西还是挺多的,
3838

3939
## 2.配置数据库连接信息和JPA配置
4040

41+
由于使用的是 h2 内存数据库,所以你直接运行项目数据库就会自动创建好。
42+
4143
下面的配置中需要单独说一下 `spring.jpa.hibernate.ddl-auto=create`这个配置选项。
4244

4345
这个属性常用的选项有四种:
@@ -50,15 +52,22 @@ JPA 这部分内容上手很容易,但是涉及到的东西还是挺多的,
5052
但是,**一定要不要在生产环境使用 ddl 自动生成表结构,一般推荐手写 SQL 语句配合 Flyway 来做这些事情。**
5153

5254
```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
5457
spring.datasource.username=root
5558
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
5663
# 打印出 sql 语句
5764
spring.jpa.show-sql=true
58-
spring.jpa.hibernate.ddl-auto=create
65+
spring.jpa.hibernate.ddl-auto=update
5966
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+
6271
```
6372

6473
## 3.实体类

0 commit comments

Comments
 (0)