Skip to content

Commit 0034376

Browse files
committed
Spring Boot 2.x基础教程:2.5版本之后的数据脚本初始化
1 parent da35cc8 commit 0034376

File tree

7 files changed

+151
-0
lines changed

7 files changed

+151
-0
lines changed

2.x/chapter3-13/.gitignore

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
HELP.md
2+
/target/
3+
!.mvn/wrapper/maven-wrapper.jar
4+
5+
### STS ###
6+
.apt_generated
7+
.classpath
8+
.factorypath
9+
.project
10+
.settings
11+
.springBeans
12+
.sts4-cache
13+
14+
### IntelliJ IDEA ###
15+
.idea
16+
*.iws
17+
*.iml
18+
*.ipr
19+
20+
### NetBeans ###
21+
/nbproject/private/
22+
/nbbuild/
23+
/dist/
24+
/nbdist/
25+
/.nb-gradle/
26+
/build/
27+
28+
### VS Code ###
29+
.vscode/

2.x/chapter3-13/pom.xml

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
3+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
4+
<modelVersion>4.0.0</modelVersion>
5+
6+
<parent>
7+
<groupId>org.springframework.boot</groupId>
8+
<artifactId>spring-boot-starter-parent</artifactId>
9+
<version>2.5.0</version>
10+
<relativePath/> <!-- lookup parent from repository -->
11+
</parent>
12+
13+
<groupId>com.didispace</groupId>
14+
<artifactId>chapter3-1(2.5+)</artifactId>
15+
<version>0.0.1-SNAPSHOT</version>
16+
17+
<properties>
18+
<java.version>1.8</java.version>
19+
</properties>
20+
21+
<dependencies>
22+
<dependency>
23+
<groupId>org.springframework.boot</groupId>
24+
<artifactId>spring-boot-starter-web</artifactId>
25+
</dependency>
26+
27+
<dependency>
28+
<groupId>org.springframework.boot</groupId>
29+
<artifactId>spring-boot-starter-jdbc</artifactId>
30+
</dependency>
31+
32+
<dependency>
33+
<groupId>mysql</groupId>
34+
<artifactId>mysql-connector-java</artifactId>
35+
</dependency>
36+
37+
<dependency>
38+
<groupId>org.projectlombok</groupId>
39+
<artifactId>lombok</artifactId>
40+
</dependency>
41+
42+
<dependency>
43+
<groupId>org.springframework.boot</groupId>
44+
<artifactId>spring-boot-starter-test</artifactId>
45+
<scope>test</scope>
46+
</dependency>
47+
</dependencies>
48+
49+
<build>
50+
<plugins>
51+
<plugin>
52+
<groupId>org.springframework.boot</groupId>
53+
<artifactId>spring-boot-maven-plugin</artifactId>
54+
</plugin>
55+
</plugins>
56+
</build>
57+
58+
</project>
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
package com.didispace.chapter313;
2+
3+
import org.springframework.boot.SpringApplication;
4+
import org.springframework.boot.autoconfigure.SpringBootApplication;
5+
6+
@SpringBootApplication
7+
public class Chapter313Application {
8+
9+
public static void main(String[] args) {
10+
SpringApplication.run(Chapter313Application.class, args);
11+
}
12+
13+
}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
spring.datasource.url=jdbc:mysql://localhost:3306/test
2+
spring.datasource.username=root
3+
spring.datasource.password=
4+
spring.datasource.driver-class-name=com.mysql.cj.jdbc.Driver
5+
6+
# Spring Boot 2.5.0 init schema & data
7+
spring.sql.init.username=root
8+
spring.sql.init.password=
9+
spring.sql.init.schema-locations=classpath*:schema-all.sql
10+
#spring.sql.init.enabled=true
11+
#spring.sql.init.data-locations=classpath*:
12+
#spring.sql.init.encoding=UTF-8
13+
#spring.sql.init.separator=;
14+
#spring.sql.init.continue-on-error=true
15+
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
create table test.user_info
2+
(
3+
id int unsigned auto_increment comment '用户id'
4+
primary key,
5+
open_id varchar(255) default '' null comment '微信小程序openid',
6+
nick_name varchar(255) default '' null comment '微信名',
7+
head_img varchar(255) default '' null comment '微信头像',
8+
sex varchar(255) default '' null comment '性别',
9+
phone varchar(255) default '' null comment '手机',
10+
province varchar(255) default '' null comment '注册地址:省',
11+
city varchar(255) default '' null comment '注册地址:城市',
12+
country varchar(255) default '' null comment '注册地址:县/区',
13+
status tinyint unsigned default 0 not null comment '是否标记删除 0:否 1:是',
14+
create_time datetime not null comment '创建时间',
15+
update_time datetime not null comment '更新时间'
16+
)
17+
comment '用户表';
18+
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
package com.didispace.chapter31;
2+
3+
import org.junit.jupiter.api.Test;
4+
import org.springframework.boot.test.context.SpringBootTest;
5+
6+
7+
@SpringBootTest
8+
public class Chapter31ApplicationTests {
9+
10+
11+
@Test
12+
public void test() throws Exception {
13+
14+
15+
}
16+
17+
}

2.x/pom.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@
4040
<module>chapter3-10</module> <!-- 事务管理入门 -->
4141
<module>chapter3-11</module> <!-- 使用Flyway管理数据库版本 -->
4242
<module>chapter3-12</module> <!-- 使用JTA -->
43+
<module>chapter3-13</module> <!--2.5版本之后的数据脚本初始化 -->
4344

4445
<!-- 3-12 使用Liquibase管理数据库版本 -->
4546
<!-- 3-13 分布式事务 -->

0 commit comments

Comments
 (0)