Skip to content

Commit 7dc7e4c

Browse files
committed
init
0 parents  commit 7dc7e4c

File tree

476 files changed

+25172
-0
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

476 files changed

+25172
-0
lines changed

Diff for: .gitignore

+34
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
HELP.md
2+
.gradle
3+
build/
4+
!gradle/wrapper/gradle-wrapper.jar
5+
!**/src/main/**
6+
!**/src/test/**
7+
8+
### STS ###
9+
.apt_generated
10+
.classpath
11+
.factorypath
12+
.project
13+
.settings
14+
.springBeans
15+
.sts4-cache
16+
17+
### IntelliJ IDEA ###
18+
.idea
19+
*.iws
20+
*.iml
21+
*.ipr
22+
out/
23+
24+
### NetBeans ###
25+
/nbproject/private/
26+
/nbbuild/
27+
/dist/
28+
/nbdist/
29+
/.nb-gradle/
30+
31+
### VS Code ###
32+
.vscode/
33+
34+
*.log

Diff for: Docs/Docs.iml

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<module type="JAVA_MODULE" version="4">
3+
<component name="NewModuleRootManager" inherit-compiler-output="true">
4+
<exclude-output />
5+
<content url="file://$MODULE_DIR$">
6+
<sourceFolder url="file://$MODULE_DIR$/src" isTestSource="false" />
7+
</content>
8+
<orderEntry type="inheritedJdk" />
9+
<orderEntry type="sourceFolder" forTests="false" />
10+
</component>
11+
</module>

Diff for: Docs/Gradle Multiple Module.md

+99
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,99 @@
1+
# Gradle 使用-多项目构建
2+
3+
## 配置
4+
> 如该项目有四个模块,分别是`Controller`, `Service`, `Dao`,`Model`,根目录仅为父级目录,不存在任何代码;子目录为各个相应的模块或单独的项目
5+
6+
- 项目根目录下添加 `build.gradle`
7+
```gradle
8+
// 子模块通用配置
9+
subprojects {
10+
apply plugin: 'java'
11+
apply plugin: 'idea'
12+
apply plugin: 'eclipse'
13+
14+
group = 'cn.com.hellowood'
15+
version = '0.0.2-SNAPSHOT'
16+
17+
sourceCompatibility = 1.8
18+
19+
// java编译的时候缺省状态下会因为中文字符而失败
20+
[compileJava, compileTestJava, javadoc]*.options*.encoding = 'UTF-8'
21+
22+
repositories {
23+
mavenLocal()
24+
maven { url 'http://maven.aliyun.com/nexus/content/groups/public/' }
25+
mavenCentral()
26+
jcenter()
27+
}
28+
29+
dependencies {
30+
testCompile 'junit:junit:4.12'
31+
}
32+
}
33+
34+
```
35+
36+
- 项目根目录下添加 `settings.gradle`
37+
```gradle
38+
rootProject.name = 'SpringBoot'
39+
40+
// 子模块
41+
include 'Controller'
42+
include 'Service'
43+
include 'Dao'
44+
include 'Model'
45+
```
46+
47+
- 子目录 `build.gradle`(其他模块类似)
48+
```gradle
49+
buildscript {
50+
ext {
51+
springBootVersion = '1.5.9.RELEASE'
52+
}
53+
repositories {
54+
mavenCentral()
55+
}
56+
dependencies {
57+
classpath("org.springframework.boot:spring-boot-gradle-plugin:${springBootVersion}")
58+
}
59+
}
60+
61+
apply plugin: 'java'
62+
apply plugin: 'eclipse'
63+
apply plugin: 'org.springframework.boot'
64+
65+
archivesBaseName = 'Controller'
66+
67+
repositories {
68+
mavenCentral()
69+
}
70+
71+
72+
dependencies {
73+
compile('org.mybatis.spring.boot:mybatis-spring-boot-starter:1.3.1')
74+
compile('org.springframework.boot:spring-boot-starter-web')
75+
compile('io.springfox:springfox-swagger2:2.7.0')
76+
compile('io.springfox:springfox-swagger-ui:2.7.0')
77+
runtime('mysql:mysql-connector-java')
78+
runtime('com.h2database:h2')
79+
testCompile('org.springframework.boot:spring-boot-starter-test')
80+
testCompile('org.springframework.restdocs:spring-restdocs-mockmvc')
81+
}
82+
83+
```
84+
85+
## 编译和使用
86+
87+
- 在根目录下执行`gradle init`
88+
- 在根目录下执行`gradle build`
89+
- 如果需要单独编译某个模块执行`gradle Controller:build`
90+
91+
92+
## 依赖其他项目
93+
- 在项目的build.gradle 文件的依赖中添加其他项目依赖
94+
95+
```
96+
dependencies {
97+
compile project(':model')
98+
}
99+
```

Diff for: Docs/SpringBood DB Migrate.md

+129
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,129 @@
1+
# SpringBoot 在启动时执行数据库脚本
2+
3+
> SpringBoot 在启动的过程中执行数据库的初始化总共有三种方式:
4+
> - 通过 SQL 脚本执行初始化
5+
> - 通过 [Flyway](https://flywaydb.org) 脚本工具执行初始化
6+
> - 通过 [Liquibase](http://www.liquibase.org/) 脚本工具执行初始化
7+
8+
## 通过 SQL 脚本
9+
10+
### 添加脚本
11+
12+
-`resources`目录下添加 `schema.sql``data.sql` 脚本
13+
`schema.sql`用于建立数据库,表等操作;`data.sql`用于向表中插入初始化数据
14+
15+
### 配置
16+
17+
-`application.properties`中添加如下配置
18+
19+
```
20+
# 应用启动时执行脚本
21+
spring.datasource.initialize=true
22+
# 当脚本出错后继续执行(避免再次启动时因SQL脚本错误而停止启动)
23+
spring.datasource.continue-on-error=true
24+
# 自定义 schema.sql 脚本位置
25+
#spring.datasource.schema=db
26+
# 自定义 data.sql 脚本位置
27+
#spring.datasource.data=db
28+
```
29+
30+
-----------------------------
31+
32+
## 通过 [Flyway](https://flywaydb.org) 执行
33+
34+
### 添加依赖
35+
```groovy
36+
compile('org.flywaydb:flyway-core')
37+
compile('org.mybatis.spring.boot:mybatis-spring-boot-starter:1.3.1')
38+
runtime('mysql:mysql-connector-java')
39+
//runtime('com.h2database:h2')
40+
```
41+
### 配置
42+
43+
- 配置数据库
44+
```
45+
# H2 数据库
46+
#spring.datasource.url=jdbc:h2:mem:test
47+
#spring.datasource.username=root
48+
#spring.datasource.password=123456
49+
#spring.datasource.driver-class-name=org.h2.Driver
50+
51+
# MySQL 数据库
52+
spring.datasource.driver-class-name=com.mysql.jdbc.Driver
53+
spring.datasource.url=jdbc:mysql://localhost:3306/product?useSSL=false
54+
spring.datasource.username=root
55+
spring.datasource.password=123456
56+
```
57+
58+
- 使用 `V_VARSION__DESCRIPTION.sql` 方式命名脚本
59+
60+
```sql
61+
CREATE TABLE product(
62+
id INT PRIMARY KEY AUTO_INCREMENT,
63+
name VARCHAR(50) NOT NULL,
64+
price DOUBLE NOT NULL DEFAULT 0
65+
);
66+
```
67+
68+
- 将 SQL 脚本放在 `resources/db/migration` 目录下,启动应用即可
69+
- 如果不想 Flyway 执行,可以配置不启用 Flyway
70+
71+
```
72+
flyway.enabled=false
73+
```
74+
75+
76+
-----------------------------
77+
78+
## 通过 [Liquibase](http://www.liquibase.org/) 执行
79+
- 添加依赖
80+
81+
```gradle
82+
compile('org.liquibase:liquibase-core')
83+
```
84+
85+
- 创建 `db/changelog/db.changelog-master.yaml`
86+
- 添加配置
87+
88+
```
89+
databaseChangeLog:
90+
- changeSet:
91+
id: 1
92+
author: marceloverdijk
93+
changes:
94+
- createTable:
95+
tableName: person
96+
columns:
97+
- column:
98+
name: id
99+
type: int
100+
autoIncrement: true
101+
constraints:
102+
primaryKey: true
103+
nullable: false
104+
- column:
105+
name: first_name
106+
type: varchar(255)
107+
constraints:
108+
nullable: false
109+
- column:
110+
name: last_name
111+
type: varchar(255)
112+
constraints:
113+
nullable: false
114+
- changeSet:
115+
id: 2
116+
author: marceloverdijk
117+
changes:
118+
- insert:
119+
tableName: person
120+
columns:
121+
- column:
122+
name: first_name
123+
value: Marcel
124+
- column:
125+
name: last_name
126+
value: Overdijk
127+
```
128+
129+
- 启动项目就会看到数据库迁移开始执行

Diff for: Docs/SpringBoot Custom Banner.md

+23
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
# SpringBoot 自定义启动 Banner
2+
3+
## 静态 Banner
4+
5+
-`resources` 下添加 `banner.txt` 文件
6+
7+
-`banner.txt` 添加内容
8+
9+
```
10+
,--. ,--.
11+
\ /-~-\ /
12+
)' a a `(
13+
( ,---. )
14+
`(_o_o_)'
15+
)`-'(
16+
17+
Spring Boot${spring-boot.formatted-version}
18+
19+
```
20+
21+
## 动态 Banner
22+
23+
-`resources` 下添加 `banner.gif` 文件

0 commit comments

Comments
 (0)