数据库文档也是交付的重要内容,本文的工具可以帮助大家快速生成相应文档,并支持多种数据库
        在企业级开发中、我们经常会有编写数据库表结构文档的时间付出,关于数据库表结构文档状态:要么没有、要么有、但都是手写、后期运维开发,需要手动进行维护到文档中,很是繁琐、如果忘记一次维护、就会给以后工作造成很多困扰、无形中制造了很多坑留给自己和后人。

screw 特点

  • 简洁、轻量、设计良好。不需要 powerdesigner 这种重量的建模工具 多数据库支持 。
  • 支持市面常见的数据库类型MySQL、Oracle、SqlServer
  • 多种格式文档。支持 MD、HTML、WORD 格式
  • 灵活扩展。支持用户自定义模板和展示样式

数据库支持

  • MySQL
  • MariaDB
  • TIDB
  • Oracle
  • SqlServer
  • PostgreSQL
  • Cache DB

文档生成支持

  • html
  • word
  • markdwon

文档截图

html

此处输入图片的描述

此处输入图片的描述

word

此处输入图片的描述

markdwon

此处输入图片的描述
此处输入图片的描述

SpringBoot整合screw生成数据库文档

代码生成(推荐)

依赖

<!--freemarker模版-->
<dependency>
<groupId>org.freemarker</groupId>
<artifactId>freemarker</artifactId>
<version>2.3.30</version>
</dependency>

<!--screw依赖-->
<dependency>
<groupId>cn.smallbun.screw</groupId>
<artifactId>screw-core</artifactId>
<version>1.0.2</version>
</dependency>

测试类代码

@SpringBootTest
public class ScrewApplicationTests {

@Test
public void contextLoads() {
//数据源:HikariCP 线程池, SpringBoot 2.0开始内置了HikariCP,2.0之前的版本需要引入依赖
HikariConfig hikariConfig = new HikariConfig();
// com.mysql.jdbc.Driver MySQL5驱动;com.mysql.cj.jdbc.Driver MySQL6之后的驱动
hikariConfig.setDriverClassName("com.mysql.jdbc.Driver");
hikariConfig.setJdbcUrl("jdbc:mysql://127.0.0.1:3306/数据库名");
hikariConfig.setUsername("数据库帐号");
hikariConfig.setPassword("数据可密码");
//设置可以获取tables remarks信息
hikariConfig.addDataSourceProperty("useInformationSchema", "true");
hikariConfig.setMinimumIdle(2);
hikariConfig.setMaximumPoolSize(5);
DataSource dataSource = new HikariDataSource(hikariConfig);

// 1、生成文件配置
EngineConfig engineConfig = EngineConfig.builder()
//生成文件路径(改成自己的生成路径)
.fileOutputDir("/Users/用户/Desktop")
//生成后是否立即打开目录
.openOutputDir(true)
//文件类型 有HTML、WORD、MD三种枚举选择
.fileType(EngineFileType.WORD)
//生成模板实现
.produceType(EngineTemplateType.freemarker).build();

// 忽略表名(可选)
List<String> ignoreTableName = Arrays.asList("aa", "test_group");
// 忽略表前缀(可选)
List<String> ignorePrefix = Collections.singletonList("czb_");
// 忽略表后缀(可选)
List<String> ignoreSuffix = Arrays.asList("_test", "_test1");

// 2、配置想要忽略的表(可选)
ProcessConfig processConfig = ProcessConfig.builder()
.ignoreTableName(ignoreTableName)
.ignoreTablePrefix(ignorePrefix)
.ignoreTableSuffix(ignoreSuffix)
.build();

// 3、生成文档配置(包含以下自定义版本号、标题、描述(数据库名 + 描述 = 文件名)等配置连接)
Configuration config = Configuration.builder()
.version("1.0.0")
.title("数据库文档")
.description("数据库设计文档生成")
.dataSource(dataSource)
.engineConfig(engineConfig)
.produceConfig(processConfig).build();

// 4、执行生成
new DocumentationExecute(config).execute();
}
}

启动run,运行测试类或contextLoads方法即可

Maven 插件生成

在pom.xml文件中加入如下配置

<build>
<plugins>
<plugin>
<groupId>cn.smallbun.screw</groupId>
<artifactId>screw-maven-plugin</artifactId>
<version>1.0.2</version>
<dependencies>
<!-- HikariCP -->
<dependency>
<groupId>com.zaxxer</groupId>
<artifactId>HikariCP</artifactId>
<version>3.4.5</version>
</dependency>
<!--mysql driver-->
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>5.1.48</version>
</dependency>
</dependencies>
<configuration>
<!--username-->
<username>数据库帐号</username>
<!--password-->
<password>数据库密码</password>
<!--driver com.mysql.jdbc.Driver MySQL5驱动;com.mysql.cj.jdbc.Driver MySQL6之后的驱动-->
<driverClassName>com.mysql.jdbc.Driver</driverClassName>
<!--jdbc url-->
<jdbcUrl>jdbc:mysql://127.0.0.1:3306/数据库名</jdbcUrl>
<!--生成文件类型 HTML、WORD、MD三种选择-->
<fileType>HTML</fileType>
<!--文件输出目录-->
<fileOutputDir>E:</fileOutputDir>
<!--打开文件输出目录-->
<openOutputDir>true</openOutputDir>
<!--生成模板-->
<produceType>freemarker</produceType>
<!--描述-->
<description>数据库文档生成</description>
<!--版本-->
<version>1.0.0</version>
<!--标题-->
<title>数据库文档</title>
</configuration>
<executions>
<execution>
<phase>compile</phase>
<goals>
<goal>run</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>

之后运行maven插件生成即可

screw 码云地址:https://gitee.com/leshalv/screw