screw 數據庫文檔生成工具


簡潔好用的數據庫表結構文檔工具

在企業級開發中、我們經常會有編寫數據庫表結構文檔的時間付出,從業以來,待過幾家企業,關於數據庫表結構文檔狀態:要么沒有、要么有、但都是手寫、后期運維開發,需要手動進行維護到文檔中,很是繁瑣、如果忘記一次維護、就會給以后工作造成很多困擾、無形中制造了很多坑留給自己和后人,於是萌生了要自己寫一個插件工具的想法,但由於自己前期在程序設計上沒有很多造詣,且能力偏低,有想法並不能很好實現,隨着工作閱歷的增加,和知識的不斷儲備,終於在2020年的3月中旬開始進行編寫,4月上旬完成初版,想完善差不多在開源,但由於工作太忙,業余時間不足,沒有在進行完善,到了6月份由於工作原因、頻繁設計和更改數據庫、經常使用自己寫的此插件、節省了很多時間,解決了很多問題 ,在僅有且不多的業余時間中、進行開源准備,於2020年6月22日,開源,歡迎大家使用、建議、並貢獻。
  關於名字,想一個太難了,好在我這個聰明的小腦瓜靈感一現,怎么突出它的小,但重要呢?從小就學過雷鋒的螺絲釘精神,摘自雷鋒日記:雖然是細小的螺絲釘,是個細微的小齒輪,然而如果缺了它,那整個的機器就無法運轉了,慢說是缺了它,即使是一枚小螺絲釘沒擰緊,一個小齒輪略有破損,也要使機器的運轉發生故障的...,感覺自己寫的這個工具,很有這意味,雖然很小、但是開發中缺了它還不行,於是便起名為screw(螺絲釘)。

特點

  • 簡潔、輕量、設計良好

  • 多數據庫支持

  • 多種格式文檔

  • 靈活擴展

  • 支持自定義模板

數據庫支持

  •  MySQL
  •  MariaDB
  •  TIDB
  •  Oracle
  •  SqlServer
  •  PostgreSQL
  •  Cache DB
  •  H2 (開發中)
  •  DB2 (開發中)
  •  HSQL (開發中)
  •  SQLite(開發中)
  •  瀚高(開發中)
  •  達夢 (開發中)
  •  虛谷 (開發中)
  •  人大金倉(開發中)

文檔生成支持

  •  html
  •  word
  •  markdwon

文檔截圖

  • html

HTML

screw-logo

  • word

word

  • markdwon

markdwon

markdwon

使用方式

普通方式

  • 引入依賴
<dependency>  <groupId>cn.smallbun.screw</groupId>  <artifactId>screw-core</artifactId>  <version>${lastVersion}</version>  </dependency>
  • 編寫代碼
/**  * 文檔生成  */ 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(); }

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>測試文檔名稱</docName>  <!--描述-->  <description>數據庫文檔生成</description>  <!--版本-->  <version>${project.version}</version>  <!--標題-->  <title>數據庫文檔</title>  </configuration>  <executions>  <execution>  <phase>compile</phase>  <goals>  <goal>run</goal>  </goals>  </execution>  </executions>  </plugin>  </plugins> </build>

使用文章

使用視頻

更多支持

WeChat WeChat QQ
微信公眾號 微信交流群 QQ交流群
  • 掃碼關注官方微信公眾號,第一時間尊享最新動向,回復 screw 獲取作者微信號。

誰在使用

名稱排序按登記先后,登記僅僅為了產品推廣,希望出現您公司名稱的小伙伴可以告訴我們。

  • 順眾數字科技(山東)有限公司
  • 江蘇立華牧業股份有限公司
  • 上海德邦物流有限公司
  • 蘭州百格網絡科技有限公司

常見問題

  • 生成后文檔亂碼?

    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>
  • MySQL數據庫表和列字段有說明、生成文檔沒有說明?

    URL鏈接加入useInformationSchema=true即可。

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

    這是因為mysql驅動版本過低造成的,升級mysql驅動版本為最新即可。

推薦開源項目

項目名稱 項目描述
api-boot 為組件化構建Api服務而生


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM