好用!一键生成数据库文档,这个开源的文档生成工具值得了解

开发 后端
6月份由于工作原因、频繁设计和更改数据库、经常使用自己写的此插件、节省了很多时间,解决了很多问题 ,在仅有且不多的业余时间中、进行开源准备,于2020年6月22日,开源,欢迎大家使用、建议、并贡献。

 简介

在企业级开发中、我们经常会有编写数据库表结构文档的时间付出,从业以来,待过几家企业,关于数据库表结构文档状态:要么没有、要么有、但都是手写、后期运维开发,需要手动进行维护到文档中,很是繁琐、如果忘记一次维护、就会给以后工作造成很多困扰、无形中制造了很多坑留给自己和后人。

于是萌生了要自己写一个插件工具的想法,但由于自己前期在程序设计上没有很多造诣,且能力偏低,有想法并不能很好实现,随着工作阅历的增加,和知识的不断储备,终于在2020年的3月中旬开始进行编写。

4月上旬完成初版,想完善差不多在开源,但由于工作太忙,业余时间不足,没有在进行完善,到了6月份由于工作原因、频繁设计和更改数据库、经常使用自己写的此插件、节省了很多时间,解决了很多问题 ,在仅有且不多的业余时间中、进行开源准备,于2020年6月22日,开源,欢迎大家使用、建议、并贡献。

关于名字,想一个太难了,好在我这个聪明的小脑瓜灵感一现,怎么突出它的小,但重要呢?从小就学过雷锋的螺丝钉精神,摘自雷锋日记:虽然是细小的螺丝钉,是个细微的小齿轮,然而如果缺了它,那整个的机器就无法运转了,慢说是缺了它,即使是一枚小螺丝钉没拧紧,一个小齿轮略有破损,也要使机器的运转发生故障的...,感觉自己写的这个工具,很有这意味,虽然很小、但是开发中缺了它还不行,于是便起名为screw(螺丝钉)。

特点

  •  简洁、轻量、设计良好
  •  多数据库支持
  •  多种格式文档
  •  灵活扩展
  •  支持自定义模板

数据库支持

  •  MySQL
  •  MariaDB
  •  TIDB
  •  Oracle
  •  SqlServer
  •  PostgreSQL
  •  Cache DB(2016)
  •  H2 (开发中)
  •  DB2  (开发中)
  •  HSQL  (开发中)
  •  SQLite(开发中)
  •  瀚高(开发中)
  •  达梦 (开发中)
  •  虚谷  (开发中)
  •  人大金仓(开发中)

文档生成支持

  •  html
  •  word
  •  markdown

文档截图

  •  html

  •  word

  •  markdwon

  

使用方式

普通方式

  •  引入依赖 
<dependency>  
    <groupId>cn.smallbun.screw</groupId>  
    <artifactId>screw-core</artifactId>  
    <version>${lastVersion}</version>  
 </dependency> 
  • 1.
  • 2.
  • 3.
  • 4.
  • 5.
  •  编写代码 
/**  
 * 文档生成  
 */  
void documentGeneration() {  
   //数据源  
   HikariConfig hikariConfig = new HikariConfig();  
   hikariConfig.setDriverClassName("com.mysql.cj.jdbc.Driver");  
   hikariConfig.setJdbcUrl("jdbc:mysql://127.0.0.1:3306/database");  
   hikariConfig.setUsername("root");  
   hikariConfig.setPassword("password");  
   //设置可以获取tables remarks信息  
   hikariConfig.addDataSourceProperty("useInformationSchema", "true");  
   hikariConfig.setMinimumIdle(2);  
   hikariConfig.setMaximumPoolSize(5);  
   DataSource dataSource = new HikariDataSource(hikariConfig);  
   //生成配置  
   EngineConfig engineConfig = EngineConfig.builder()  
         //生成文件路径  
         .fileOutputDir(fileOutputDir)  
         //打开目录  
         .openOutputDir(true)  
         //文件类型  
         .fileType(EngineFileType.HTML)  
         //生成模板实现  
         .produceType(EngineTemplateType.freemarker)  
         //自定义文件名称  
         .fileName("自定义文件名称").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();  

  • 1.
  • 2.
  • 3.
  • 4.
  • 5.
  • 6.
  • 7.
  • 8.
  • 9.
  • 10.
  • 11.
  • 12.
  • 13.
  • 14.
  • 15.
  • 16.
  • 17.
  • 18.
  • 19.
  • 20.
  • 21.
  • 22.
  • 23.
  • 24.
  • 25.
  • 26.
  • 27.
  • 28.
  • 29.
  • 30.
  • 31.
  • 32.
  • 33.
  • 34.
  • 35.
  • 36.
  • 37.
  • 38.
  • 39.
  • 40.
  • 41.
  • 42.
  • 43.
  • 44.
  • 45.
  • 46.
  • 47.
  • 48.
  • 49.
  • 50.
  • 51.
  • 52.
  • 53.
  • 54.
  • 55.
  • 56.
  • 57.
  • 58.
  • 59.
  • 60.
  • 61.
  • 62.
  • 63.
  • 64.
  • 65.
  • 66.
  • 67.

Maven 插件 

<build>  
    <plugins>  
        <plugin>  
            <groupId>cn.smallbun.screw</groupId>  
            <artifactId>screw-maven-plugin</artifactId>  
            <version>${lastVersion}</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>8.0.20</version>  
                </dependency>  
            </dependencies>  
            <configuration>  
                <!--username-->  
                <username>root</username>  
                <!--password-->  
                <password>password</password>  
                <!--driver-->  
                <driverClassName>com.mysql.cj.jdbc.Driver</driverClassName>  
                <!--jdbc url-->  
                <jdbcUrl>jdbc:mysql://127.0.0.1:3306/xxxx</jdbcUrl>  
                <!--生成文件类型-->  
                <fileType>HTML</fileType>  
                <!--打开文件输出目录-->  
                <openOutputDir>false</openOutputDir>  
                <!--生成模板-->  
                <produceType>freemarker</produceType>  
                <!--文档名称 为空时:将采用[数据库名称-描述-版本号]作为文档名称-->  
                <fileName>测试文档名称</fileName>  
                <!--描述-->  
                <description>数据库文档生成</description>  
                <!--版本-->  
                <version>${project.version}</version>  
                <!--标题-->  
                <title>数据库文档</title>  
            </configuration> 
             <executions>  
                <execution>  
                    <phase>compile</phase>  
                    <goals>  
                        <goal>run</goal>  
                    </goals>  
                </execution>  
            </executions>  
        </plugin>  
    </plugins>  
</build> 
  • 1.
  • 2.
  • 3.
  • 4.
  • 5.
  • 6.
  • 7.
  • 8.
  • 9.
  • 10.
  • 11.
  • 12.
  • 13.
  • 14.
  • 15.
  • 16.
  • 17.
  • 18.
  • 19.
  • 20.
  • 21.
  • 22.
  • 23.
  • 24.
  • 25.
  • 26.
  • 27.
  • 28.
  • 29.
  • 30.
  • 31.
  • 32.
  • 33.
  • 34.
  • 35.
  • 36.
  • 37.
  • 38.
  • 39.
  • 40.
  • 41.
  • 42.
  • 43.
  • 44.
  • 45.
  • 46.
  • 47.
  • 48.
  • 49.
  • 50.
  • 51.
  • 52.
  • 53.
  • 54.
  • 55.

扩展模块

pojo生成功能

功能简介

pojo生成功能是基于screw延伸出的扩展模块,目前处于初步开发的状态。在日常的开发中,经过需求分析、建模之后,往往会先在数据库中建表,其次在进行代码的开发。那么pojo生成功能在这个阶段就可以帮助大家节省一些重复劳动了。

使用pojo生成功能可以直接根据数据库生成对应的java pojo对象。这样后续的修改,开发都会很方便。

数据库支持

  •  MySQL

使用方式

  •  引入依赖 
<dependency>  
    <groupId>cn.smallbun.screw</groupId>  
    <artifactId>screw-extension</artifactId>  
    <version>${lastVersion}</version>  
 </dependency> 
  • 1.
  • 2.
  • 3.
  • 4.
  • 5.
  •  编写代码 
/**  
 * pojo生成  
 */  
void pojoGeneration() {  
    //数据源  
    HikariConfig hikariConfig = new HikariConfig();  
    hikariConfig.setDriverClassName("com.mysql.cj.jdbc.Driver");  
    hikariConfig.setJdbcUrl("jdbc:mysql://127.0.0.1:3306/screw");  
    hikariConfig.setUsername("screw");  
    hikariConfig.setPassword("screw");  
    //设置可以获取tables remarks信息 
     hikariConfig.addDataSourceProperty("useInformationSchema", "true");  
    hikariConfig.setMinimumIdle(2);  
    hikariConfig.setMaximumPoolSize(5);  
    DataSource dataSource = new HikariDataSource(hikariConfig);  
    ProcessConfig processConfig = ProcessConfig.builder()  
        //指定生成逻辑、当存在指定表、指定表前缀、指定表后缀时,将生成指定表,其余表不生成、并跳过忽略表配置  
        //根据名称指定表生成  
        .designatedTableName(new ArrayList<>())  
        //根据表前缀生成  
        .designatedTablePrefix(new ArrayList<>())  
        //根据表后缀生成  
        .designatedTableSuffix(new ArrayList<>()).build();  
    //设置生成pojo相关配置  
    PojoConfiguration config = new PojoConfiguration();  
    //设置文件存放路径  
    config.setPath("/cn/smallbun/screw/");  
    //设置包名  
    config.setPackageName("cn.smallbun.screw");  
    //设置是否使用lombok  
    config.setUseLombok(false);  
    //设置数据源  
    config.setDataSource(dataSource);  
    //设置命名策略  
    config.setNameStrategy(new HumpNameStrategy());  
    //设置表过滤逻辑  
    config.setProcessConfig(processConfig);  
    //执行生成  
    new PojoExecute(config).execute();  

  • 1.
  • 2.
  • 3.
  • 4.
  • 5.
  • 6.
  • 7.
  • 8.
  • 9.
  • 10.
  • 11.
  • 12.
  • 13.
  • 14.
  • 15.
  • 16.
  • 17.
  • 18.
  • 19.
  • 20.
  • 21.
  • 22.
  • 23.
  • 24.
  • 25.
  • 26.
  • 27.
  • 28.
  • 29.
  • 30.
  • 31.
  • 32.
  • 33.
  • 34.
  • 35.
  • 36.
  • 37.
  • 38.
  • 39.
  • 40.

常见问题

  •  生成后文档乱码?

          MySQL:URL加入?characterEncoding=UTF-8。

  •  Caused by: java.lang.NoSuchFieldError: VERSION_2_3_30?

           检查项目freemarker依赖,这是由于版本过低造成的,升级版本为2.3.30即可。

  •  java.lang.AbstractMethodError: oracle.jdbc.driver.T4CConnection.getSchema()Ljava/lang/String;

          这是因为oracle驱动版本过低造成的,删除或屏蔽目前驱动版本,驱动添加升级为以下版本:   

<dependency>  
       <groupId>com.oracle.ojdbc</groupId>  
       <artifactId>ojdbc8</artifactId>  
       <version>19.3.0.0</version>  
    </dependency>  
    <dependency>  
       <groupId>cn.easyproject</groupId>  
       <artifactId>orai18n</artifactId>  
       <version>12.1.0.2.0</version>  
    </dependency> 
  • 1.
  • 2.
  • 3.
  • 4.
  • 5.
  • 6.
  • 7.
  • 8.
  • 9.
  • 10.
  •  MySQL数据库表和列字段有说明、生成文档没有说明?

    URL链接加入useInformationSchema=true即可。

  •  java.lang.AbstractMethodError: com.mysql.jdbc.JDBC4Connection.getSchema()Ljava/lang/String;

    这是因为mysql驱动版本过低造成的,升级mysql驱动版本为最新即可。 

 

责任编辑:庞桂玉 来源: Java知音
相关推荐

2020-08-06 11:45:37

数据库文档Swagger

2023-03-29 07:02:46

开源项目工具

2024-08-13 10:36:25

SpringScrew数据库

2020-07-29 10:55:07

数据库工具技术

2018-10-09 14:34:58

开源KubernetesGit

2024-04-08 14:07:51

Animagine开源

2010-05-07 14:29:45

Unix--Tripw

2021-05-10 09:22:44

.NET数据库项目

2024-09-30 08:10:22

2023-06-01 15:30:30

Service代码生成工具

2024-06-21 10:27:21

Service生成工具鸿蒙

2016-08-23 13:35:22

MVCEFNuGet

2021-04-16 07:31:50

工具Postman接口

2024-07-04 10:13:18

2023-04-18 18:22:31

开源工具数据库

2024-06-21 10:07:06

鸿蒙service生成工具

2021-01-04 09:00:00

JavaScript开发Web

2019-10-11 11:00:53

Nginx神器前端

2022-08-02 14:27:01

HDF驱动框架驱动开发

2024-03-15 14:34:12

Oracle数据库一键巡检
点赞
收藏

51CTO技术栈公众号