创建项目
项目目录结构
POM文件
<?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 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.5.4</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<groupId>com.myron.doc</groupId>
<artifactId>springboot-datasource-doc</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>springboot-datasource-doc</name>
<description>springboot-datasource-doc</description>
<properties>
<java.version>1.8</java.version>
</properties>
<dependencies>
<!-- SpringBoot开发起步依赖 -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<!-- 数据源 -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-jdbc</artifactId>
</dependency>
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<scope>runtime</scope>
</dependency>
<!-- 测试 -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<!-- 文档生成工具 -->
<dependency>
<groupId>org.freemarker</groupId>
<artifactId>freemarker</artifactId>
<version>2.3.30</version>
</dependency>
<dependency>
<groupId>cn.smallbun.screw</groupId>
<artifactId>screw-core</artifactId>
<version>1.0.5</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-test</artifactId>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
</project>
Test.java
package com.myron.doc.springbootdatasourcedoc;
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.List;
public class Test
{
public static void main(String[] args) {
// 数据源
HikariConfig hikariConfig = new HikariConfig();
hikariConfig.setDriverClassName("com.mysql.cj.jdbc.Driver");
hikariConfig.setJdbcUrl("jdbc:mysql://127.0.0.1:3306/bjd");
hikariConfig.setUsername("root");
hikariConfig.setPassword("root");
// 设置可以获取tables remarks信息
hikariConfig.addDataSourceProperty("useInformationSchema", "true");
hikariConfig.setMinimumIdle(2);
hikariConfig.setMaximumPoolSize(5);
DataSource dataSource = new HikariDataSource(hikariConfig);
// 1、生成文件配置
EngineConfig engineConfig = EngineConfig.builder()
// 生成文件路径
.fileOutputDir("C:\\Users\\Administrator\\Desktop")
// 打开目录
.openOutputDir(false)
// 文件类型
.fileType(EngineFileType.MD) // 文件类型,支持html,markdown,word类型
// 生成模板实现
.produceType(EngineTemplateType.freemarker).build();
// 忽略表名
List<String> ignoreTableName = Arrays.asList("test");
// 忽略表前缀
List<String> ignorePrefix = Arrays.asList("test_", "test");
// 忽略表后缀
List<String> ignoreSuffix = Arrays.asList("_test", "test");
// 2、配置想要忽略的表
ProcessConfig processConfig = ProcessConfig.builder().ignoreTableName(ignoreTableName)
.ignoreTablePrefix(ignorePrefix).ignoreTableSuffix(ignoreSuffix).build();
// 3、生成文档配置(包含以下自定义版本号、描述等配置连接)
Configuration config = Configuration.builder().version("1.0.0").description("数据库文档").dataSource(dataSource)
.engineConfig(engineConfig).produceConfig(processConfig).build();
// 4、执行生成
new DocumentationExecute(config).execute();
}
}
生成文件类型,支持html,markdown,word类型
HMTL
WORD 没表表目录
markdown 直接拖到idea查看
sublime,MarkdownPad无法查看,不知是生成的文件有不规范,还是这两个软件无法解析。