Screw - 数据库表结构文档生成器

Screw-自动化程度高,能快速生成文档,减少手动编写的工作量

支持多种数据库生成HTML、Word、MarkDown 三种格式的文档

在这里插入图片描述

快速上手,以Oracle方式为例

第一种方式:Maven 插件

1、引入

<build>
        <plugins>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
            </plugin>
            <plugin>
                <groupId>cn.smallbun.screw</groupId>
                <artifactId>screw-maven-plugin</artifactId>
                <version>1.0.5</version>
                <dependencies>
                    <!-- HikariCP -->
                    <dependency>
                        <groupId>com.zaxxer</groupId>
                        <artifactId>HikariCP</artifactId>
                        <version>3.4.5</version>
                    </dependency>
                    <!--oracle driver-->
                    <dependency>
                        <groupId>com.oracle</groupId>
                        <artifactId>ojdbc8</artifactId>
                        <version>12.2.0.1.0</version>
                    </dependency>
                </dependencies>
                <configuration>
                    <!-- 数据库用户名 -->
                    <username>LIVE7042TST</username>
                    <!--<type>com.alibaba.druid.pool.DruidDataSource</type>-->
                    <!-- 数据库密码 -->
                    <password>EBR</password>
                    <!-- 数据库驱动  oracle.jdbc.driver.OracleDriver-->
                    <driverClassName>oracle.jdbc.driver.OracleDriver</driverClassName>
                    <!-- 数据库连接地址 -->
                    <jdbcUrl>jdbc:oracle:thin:@192.168.85.163:1521/EBR19C</jdbcUrl>
                    <!-- 生成的文件类型 HTML、WORD、MD 三种类型 -->
                    <fileType>HTML</fileType>
                    <!-- 打开文件输出目录 -->
                    <openOutputDir>false</openOutputDir>
                    <!-- 生成模板 -->
                    <produceType>freemarker</produceType>
                    <!-- 文档名称 为空时:将采用[数据库名称-描述-版本号]作为文档名称 -->
                    <fileName>数据库文档</fileName>
                    <!-- 描述 -->
                    <description>数据库文档</description>
                    <!-- 版本 -->
                    <version>20240619</version>
                    <!-- 标题 -->
                    <title>数据库文档</title>
                </configuration>
                <executions>
                    <execution>
                        <phase>compile</phase>
                        <goals>
                            <goal>run</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>
        </plugins>
    </build>

2、执行插件
在这里插入图片描述
3、生成
点击 刷新-生成成功
在这里插入图片描述

第二种方式:代码生成

示例:以MySQL为例
1、引入依赖

<!-- 引入数据库驱动,这里以 MySQL 为例 -->
<dependency>
    <groupId>mysql</groupId>
    <artifactId>mysql-connector-java</artifactId>
    <version>8.0.29</version>
</dependency>

<!-- 引入 screw -->
<dependency>
    <groupId>cn.smallbun.screw</groupId>
    <artifactId>screw-core</artifactId>
    <version>1.0.5</version>
 </dependency>

2、编写测试类

public class DocumentGenera {

    /**
     * 文档生成
     */
    @Test
    public void documentGenera() {

        // 文档生成路径
        String fileOutputPath = "C:\\database";

        // 数据源
        HikariConfig hikariConfig = new HikariConfig();
        // 指定数据库驱动
        hikariConfig.setDriverClassName("com.mysql.cj.jdbc.Driver");
        // 设置数据库连接地址
        hikariConfig.setJdbcUrl("jdbc:mysql://localhost:3306/test");
        // 设置数据库用户
        hikariConfig.setUsername("root");
        // 设置数据库密码
        hikariConfig.setPassword("root");
        // 设置可以获取 tables remarks 信息
        hikariConfig.addDataSourceProperty("useInformationSchema", "true");
        hikariConfig.setMinimumIdle(2);
        hikariConfig.setMaximumPoolSize(5);

        DataSource dataSource = new HikariDataSource(hikariConfig);
        // 生成配置
        EngineConfig engineConfig = EngineConfig.builder()
                // 生成文件路径
                .fileOutputDir(fileOutputPath)
                // 打开目录
                .openOutputDir(true)
                // 文件类型 HTML、WORD、MD 三种类型
                .fileType(EngineFileType.HTML)
                // 生成模板实现
                .produceType(EngineTemplateType.freemarker)
                // 自定义文件名称
                .fileName("Document")
                .build();

        // 忽略表
        ArrayList<String> ignoreTableName = new ArrayList<>();
        ignoreTableName.add("test_user");
        ignoreTableName.add("test_group");

        //忽略表前缀
        ArrayList<String> ignorePrefix = new ArrayList<>();
        ignorePrefix.add("test_");

        //忽略表后缀
        ArrayList<String> ignoreSuffix = new ArrayList<>();
        ignoreSuffix.add("_test");

        ProcessConfig processConfig = ProcessConfig.builder()
                // 指定生成逻辑、当存在指定表、指定表前缀、指定表后缀时,将生成指定表,其余表不生成、并跳过忽略表配置
                // 根据名称指定表生成
                .designatedTableName(new ArrayList<>())
                // 根据表前缀生成
                .designatedTablePrefix(new ArrayList<>())
                // 根据表后缀生成
                .designatedTableSuffix(new ArrayList<>())
                // 忽略表名
                .ignoreTableName(ignoreTableName)
                // 忽略表前缀
                .ignoreTablePrefix(ignorePrefix)
                // 忽略表后缀
                .ignoreTableSuffix(ignoreSuffix)
                .build();
        //配置
        Configuration config = Configuration.builder()
                // 版本
                .version("1.0.0")
                // 描述
                .description("数据库设计文档生成")
                // 数据源
                .dataSource(dataSource)
                // 生成配置
                .engineConfig(engineConfig)
                // 生成配置
                .produceConfig(processConfig)
                .build();

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

3、执行代码输出文档-生成成功
在这里插入图片描述

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

石马农汪

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值