forked from yudaocode/SpringBoot-Labs
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
YunaiV
committed
Dec 12, 2020
1 parent
b8e503e
commit 7ceb293
Showing
4 changed files
with
142 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<project xmlns="http://maven.apache.org/POM/4.0.0" | ||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> | ||
<parent> | ||
<artifactId>lab-70-db-doc</artifactId> | ||
<groupId>cn.iocoder.springboot.labs</groupId> | ||
<version>1.0-SNAPSHOT</version> | ||
</parent> | ||
<modelVersion>4.0.0</modelVersion> | ||
|
||
<artifactId>lab-70-db-doc-screw-01</artifactId> | ||
|
||
|
||
|
||
<dependencies> | ||
<!-- screw 库,简洁好用的数据库表结构文档生成器 --> | ||
<dependency> | ||
<groupId>cn.smallbun.screw</groupId> | ||
<artifactId>screw-core</artifactId> | ||
<version>1.0.5</version> | ||
</dependency> | ||
|
||
<!-- 数据库连接 --> | ||
<dependency> | ||
<groupId>com.zaxxer</groupId> | ||
<artifactId>HikariCP</artifactId> | ||
<version>3.4.5</version> | ||
</dependency> | ||
<dependency> | ||
<groupId>mysql</groupId> | ||
<artifactId>mysql-connector-java</artifactId> | ||
<version>8.0.22</version> | ||
</dependency> | ||
</dependencies> | ||
|
||
</project> |
84 changes: 84 additions & 0 deletions
84
lab-70-db-doc/lab-70-db-doc-screw-01/src/main/java/ScrewMain.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
import cn.smallbun.screw.core.Configuration; | ||
import cn.smallbun.screw.core.engine.EngineConfig; | ||
import cn.smallbun.screw.core.engine.EngineFileType; | ||
import cn.smallbun.screw.core.engine.EngineTemplateType; | ||
import cn.smallbun.screw.core.execute.DocumentationExecute; | ||
import cn.smallbun.screw.core.process.ProcessConfig; | ||
import com.zaxxer.hikari.HikariConfig; | ||
import com.zaxxer.hikari.HikariDataSource; | ||
|
||
import javax.sql.DataSource; | ||
import java.util.Arrays; | ||
import java.util.Collections; | ||
|
||
public class ScrewMain { | ||
|
||
private static final String DB_URL = "jdbc:mysql://400-infra.server.iocoder.cn:3306"; | ||
private static final String DB_NAME = "mall_system"; | ||
private static final String DB_USERNAME = "root"; | ||
private static final String DB_PASSWORD = "3WLiVUBEwTbvAfsh"; | ||
|
||
private static final String FILE_OUTPUT_DIR = "/Users/yunai/screw_test"; | ||
private static final EngineFileType FILE_OUTPUT_TYPE = EngineFileType.HTML; // 可以设置 WORD 或者 Markdown 格式 | ||
private static final String DOC_FILE_NAME = "数据库文档"; | ||
private static final String DOC_VERSION = "1.0.0"; | ||
private static final String DOC_DESCRIPTION = "文档描述"; | ||
|
||
public static void main(String[] args) { | ||
// 创建 screw 的配置 | ||
Configuration config = Configuration.builder() | ||
.version(DOC_VERSION) // 版本 | ||
.description(DOC_DESCRIPTION) // 描述 | ||
.dataSource(buildDataSource()) // 数据源 | ||
.engineConfig(buildEngineConfig()) // 引擎配置 | ||
.produceConfig(buildProcessConfig()) // 处理配置 | ||
.build(); | ||
|
||
// 执行 screw,生成数据库文档 | ||
new DocumentationExecute(config).execute(); | ||
} | ||
|
||
/** | ||
* 创建数据源 | ||
*/ | ||
private static DataSource buildDataSource() { | ||
// 创建 HikariConfig 配置类 | ||
HikariConfig hikariConfig = new HikariConfig(); | ||
hikariConfig.setDriverClassName("com.mysql.cj.jdbc.Driver"); | ||
hikariConfig.setJdbcUrl(DB_URL + "/" + DB_NAME); | ||
hikariConfig.setUsername(DB_USERNAME); | ||
hikariConfig.setPassword(DB_PASSWORD); | ||
hikariConfig.addDataSourceProperty("useInformationSchema", "true"); // 设置可以获取 tables remarks 信息 | ||
// 创建数据源 | ||
return new HikariDataSource(hikariConfig); | ||
} | ||
|
||
/** | ||
* 创建 screw 的引擎配置 | ||
*/ | ||
private static EngineConfig buildEngineConfig() { | ||
return EngineConfig.builder() | ||
.fileOutputDir(FILE_OUTPUT_DIR) // 生成文件路径 | ||
.openOutputDir(false) // 打开目录 | ||
.fileType(FILE_OUTPUT_TYPE) // 文件类型 | ||
.produceType(EngineTemplateType.freemarker) // 文件类型 | ||
.fileName(DOC_FILE_NAME) // 自定义文件名称 | ||
.build(); | ||
} | ||
|
||
/** | ||
* 创建 screw 的处理配置,一般可忽略 | ||
* 指定生成逻辑、当存在指定表、指定表前缀、指定表后缀时,将生成指定表,其余表不生成、并跳过忽略表配置 | ||
*/ | ||
private static ProcessConfig buildProcessConfig() { | ||
return ProcessConfig.builder() | ||
.designatedTableName(Collections.<String>emptyList()) // 根据名称指定表生成 | ||
.designatedTablePrefix(Collections.<String>emptyList()) //根据表前缀生成 | ||
.designatedTableSuffix(Collections.<String>emptyList()) // 根据表后缀生成 | ||
.ignoreTableName(Arrays.asList("test_user", "test_group")) // 忽略表名 | ||
.ignoreTablePrefix(Collections.singletonList("test_")) // 忽略表前缀 | ||
.ignoreTableSuffix(Collections.singletonList("_test")) // 忽略表后缀 | ||
.build(); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<project xmlns="http://maven.apache.org/POM/4.0.0" | ||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> | ||
<parent> | ||
<artifactId>labs-parent</artifactId> | ||
<groupId>cn.iocoder.springboot.labs</groupId> | ||
<version>1.0-SNAPSHOT</version> | ||
</parent> | ||
<modelVersion>4.0.0</modelVersion> | ||
|
||
<artifactId>lab-70-db-doc</artifactId> | ||
<packaging>pom</packaging> | ||
|
||
<modules> | ||
<module>lab-70-db-doc-screw-01</module> | ||
</modules> | ||
|
||
</project> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters