永不生锈的螺丝钉!一款简洁好用的数据库表结构文档生成器 ...

打印 上一主题 下一主题

主题 917|帖子 917|积分 2751

大家好,我是 Java陈序员。
在企业级开辟中,我们经常会有编写数据库表结构文档的需求,经常必要手写维护文档,非常繁琐。
今天,给大家介绍一款数据库表结构文档生成工具。
关注微信公众号:【Java陈序员】,获取开源项目分享、AI副业分享、超200本经典盘算机电子书籍等。
项目介绍

screw  —— 螺丝钉(代表企业级开辟中一颗永不生锈的螺丝钉),是一款简洁好用的数据库表结构文档生成工具。

screw  主打简洁、轻量,支持多种数据库、多种格式文档,可自界说模板举行机动拓展。

  • 支持 MySQL、MariaDB、TIDB、Oracle 多种数据库


  • 支持生成 HTML、Word、MarkDown 三种格式的文档

快速上手

screw  有普通方式Maven 插件的两种方式来生成文档。
普通方式

1、引入依靠
  1. <dependency>
  2.     <groupId>mysql</groupId>
  3.     <artifactId>mysql-connector-java</artifactId>
  4.     <version>8.0.29</version>
  5. </dependency>
  6. <dependency>
  7.     <groupId>cn.smallbun.screw</groupId>
  8.     <artifactId>screw-core</artifactId>
  9.     <version>1.0.5</version>
  10. </dependency>
复制代码
2、编写代码
  1. public class DocumentGeneration {
  2.     /**
  3.      * 文档生成
  4.      */
  5.     @Test
  6.     public void documentGeneration() {
  7.         // 文档生成路径
  8.         String fileOutputPath = "D:\\database";
  9.         // 数据源
  10.         HikariConfig hikariConfig = new HikariConfig();
  11.         // 指定数据库驱动
  12.         hikariConfig.setDriverClassName("com.mysql.cj.jdbc.Driver");
  13.         // 设置数据库连接地址
  14.         hikariConfig.setJdbcUrl("jdbc:mysql://localhost:3306/database");
  15.         // 设置数据库用户
  16.         hikariConfig.setUsername("root");
  17.         // 设置数据库密码
  18.         hikariConfig.setPassword("root");
  19.         // 设置可以获取 tables remarks 信息
  20.         hikariConfig.addDataSourceProperty("useInformationSchema", "true");
  21.         hikariConfig.setMinimumIdle(2);
  22.         hikariConfig.setMaximumPoolSize(5);
  23.         DataSource dataSource = new HikariDataSource(hikariConfig);
  24.         // 生成配置
  25.         EngineConfig engineConfig = EngineConfig.builder()
  26.                 // 生成文件路径
  27.                 .fileOutputDir(fileOutputPath)
  28.                 // 打开目录
  29.                 .openOutputDir(true)
  30.                 // 文件类型 HTML、WORD、MD 三种类型
  31.                 .fileType(EngineFileType.HTML)
  32.                 // 生成模板实现
  33.                 .produceType(EngineTemplateType.freemarker)
  34.                 // 自定义文件名称
  35.                 .fileName("Document")
  36.                 .build();
  37.         // 忽略表
  38.         ArrayList<String> ignoreTableName = new ArrayList<>();
  39.         ignoreTableName.add("test_user");
  40.         ignoreTableName.add("test_group");
  41.         //忽略表前缀
  42.         ArrayList<String> ignorePrefix = new ArrayList<>();
  43.         ignorePrefix.add("test_");
  44.         //忽略表后缀
  45.         ArrayList<String> ignoreSuffix = new ArrayList<>();
  46.         ignoreSuffix.add("_test");
  47.         ProcessConfig processConfig = ProcessConfig.builder()
  48.                 // 指定生成逻辑、当存在指定表、指定表前缀、指定表后缀时,将生成指定表,其余表不生成、并跳过忽略表配置
  49.                 // 根据名称指定表生成
  50.                 .designatedTableName(new ArrayList<>())
  51.                 // 根据表前缀生成
  52.                 .designatedTablePrefix(new ArrayList<>())
  53.                 // 根据表后缀生成
  54.                 .designatedTableSuffix(new ArrayList<>())
  55.                 // 忽略表名
  56.                 .ignoreTableName(ignoreTableName)
  57.                 // 忽略表前缀
  58.                 .ignoreTablePrefix(ignorePrefix)
  59.                 // 忽略表后缀
  60.                 .ignoreTableSuffix(ignoreSuffix)
  61.                 .build();
  62.         //配置
  63.         Configuration config = Configuration.builder()
  64.                 // 版本
  65.                 .version("1.0.0")
  66.                 // 描述
  67.                 .description("数据库设计文档生成")
  68.                 // 数据源
  69.                 .dataSource(dataSource)
  70.                 // 生成配置
  71.                 .engineConfig(engineConfig)
  72.                 // 生成配置
  73.                 .produceConfig(processConfig)
  74.                 .build();
  75.         //执行生成
  76.         new DocumentationExecute(config).execute();
  77.     }
  78. }
复制代码
3、实行代码输出文档

Maven 插件

1、引入依靠
  1. <build>
  2.     <plugins>
  3.         <plugin>
  4.             <groupId>cn.smallbun.screw</groupId>
  5.             <artifactId>screw-maven-plugin</artifactId>
  6.             <version>1.0.5</version>
  7.             <dependencies>
  8.                
  9.                 <dependency>
  10.                     <groupId>com.zaxxer</groupId>
  11.                     <artifactId>HikariCP</artifactId>
  12.                     <version>3.4.5</version>
  13.                 </dependency>
  14.                
  15.                 <dependency>
  16.                     <groupId>mysql</groupId>
  17.                     <artifactId>mysql-connector-java</artifactId>
  18.                     <version>8.0.20</version>
  19.                 </dependency>
  20.             </dependencies>
  21.             <configuration>
  22.                
  23.                 <username>root</username>
  24.                
  25.                 <password>password</password>
  26.                
  27.                 <driverClassName>com.mysql.cj.jdbc.Driver</driverClassName>
  28.                
  29.                 <jdbcUrl>jdbc:mysql://127.0.0.1:3306/xxxx</jdbcUrl>
  30.                
  31.                 <fileType>HTML</fileType>
  32.                
  33.                 <openOutputDir>false</openOutputDir>
  34.                
  35.                 <produceType>freemarker</produceType>
  36.                
  37.                 <fileName>数据库文档</fileName>
  38.                
  39.                 <description>数据库文档生成</description>
  40.                
  41.                 <version>${project.version}</version>
  42.                
  43.                 <title>数据库文档</title>
  44.             </configuration>
  45.             <executions>
  46.                 <execution>
  47.                     <phase>compile</phase>
  48.                     <goals>
  49.                         <goal>run</goal>
  50.                     </goals>
  51.                 </execution>
  52.             </executions>
  53.         </plugin>
  54.     </plugins>
  55. </build>
复制代码
2、实行插件

3、使用 Maven 插件实行的方式会将文档输出到项目根目录的 doc 目录下

文档截图

HTML 范例文档

Word 范例文档

MarkDown 范例文档

自从用了 screw  后,编写数据库文档信息就很方便了,一键生成,剩下的时间就可以用来摸鱼了~
大家如果下次有必要编写数据库文档,可以考虑使用 screw ,建议先把本文收藏起来,下次就不会找不到了~
最后,贴上项目地址:
  1. https://github.com/pingfangushi/screw
复制代码
最后

推荐的开源项目已经收录到 GitHub 项目,欢迎 Star:
  1. https://github.com/chenyl8848/great-open-source-project
复制代码
大概访问网站,举行在线欣赏:
  1. https://chencoding.top:8090/#/
复制代码
大家的点赞、收藏和批评都是对作者的支持,如文章对你有帮助还请点赞转发支持下,谢谢!

免责声明:如果侵犯了您的权益,请联系站长,我们会及时删除侵权内容,谢谢合作!更多信息从访问主页:qidao123.com:ToB企服之家,中国第一个企服评测及商务社交产业平台。

本帖子中包含更多资源

您需要 登录 才可以下载或查看,没有账号?立即注册

x
回复

使用道具 举报

0 个回复

倒序浏览

快速回复

您需要登录后才可以回帖 登录 or 立即注册

本版积分规则

tsx81429

金牌会员
这个人很懒什么都没写!
快速回复 返回顶部 返回列表