還在手動整理數(shù)據(jù)庫文檔?試試這個工具
作者:冷冷 
  在企業(yè)級開發(fā)中、我們經(jīng)常會有編寫數(shù)據(jù)庫表結構文檔的時間付出,從業(yè)以來,待過幾家企業(yè),關于數(shù)據(jù)庫表結構文檔狀態(tài):要么沒有、要么有、但都是手寫、后期運維開發(fā),需要手動進行維護到文檔中,很是繁瑣。
 
簡介
在企業(yè)級開發(fā)中、我們經(jīng)常會有編寫數(shù)據(jù)庫表結構文檔的時間付出,從業(yè)以來,待過幾家企業(yè),關于數(shù)據(jù)庫表結構文檔狀態(tài):要么沒有、要么有、但都是手寫、后期運維開發(fā),需要手動進行維護到文檔中,很是繁瑣、如果忘記一次維護、就會給以后工作造成很多困擾、無形中制造了很多坑留給自己和后人,于是需要一個插件工具screw[1]來維護。
screw 特點
- 簡潔、輕量、設計良好。不需要 powerdesigner 這種重量的建模工具
 - 多數(shù)據(jù)庫支持 。支持市面常見的數(shù)據(jù)庫類型 MySQL、Oracle、SqlServer
 - 多種格式文檔。支持 MD、HTML、WORD 格式
 - 靈活擴展。支持用戶自定義模板和展示樣式
 
支持數(shù)據(jù)庫類型
- [✔️] MySQL
 - [✔️] MariaDB
 - [✔️] TIDB
 - [✔️] Oracle
 - [✔️] SqlServer
 - [✔️] PostgreSQL
 - [✔️] Cache DB
 
依賴
這里以 mysql8 數(shù)據(jù)庫為例子
- <!--數(shù)據(jù)庫文檔核心依賴-->
 - <dependency>
 - <groupId>cn.smallbun.screw</groupId>
 - <artifactId>screw-core</artifactId>
 - <version>1.0.2</version>
 - </dependency>
 - <!-- 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>
 
1. 通過自定義代碼配置文檔生成
- @Test
 - public void shouldAnswerWithTrue() {
 - //數(shù)據(jù)源
 - HikariConfig hikariConfig = new HikariConfig();
 - hikariConfig.setDriverClassName("com.mysql.cj.jdbc.Driver");
 - hikariConfig.setJdbcUrl("jdbc:mysql://127.0.0.1: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("/Users/lengleng")
 - //打開目錄
 - .openOutputDir(true)
 - //文件類型
 - .fileType(EngineFileType.HTML)
 - //生成模板實現(xiàn)
 - .produceType(EngineTemplateType.freemarker).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()
 - //忽略表名
 - .ignoreTableName(ignoreTableName)
 - //忽略表前綴
 - .ignoreTablePrefix(ignorePrefix)
 - //忽略表后綴
 - .ignoreTableSuffix(ignoreSuffix).build();
 - //配置
 - Configuration config = Configuration.builder()
 - //版本
 - .version("1.0.0")
 - //描述
 - .description("數(shù)據(jù)庫設計文檔生成")
 - //數(shù)據(jù)源
 - .dataSource(dataSource)
 - //生成配置
 - .engineConfig(engineConfig)
 - //生成配置
 - .produceConfig(processConfig).build();
 - //執(zhí)行生成
 - new DocumentationExecute(config).execute();
 - }
 
2. 通過插件的形式生成文檔
- <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>8.0.20</version>
 - </dependency>
 - </dependencies>
 - <configuration>
 - <!--username-->
 - <username>root</username>
 - <!--password-->
 - <password>root</password>
 - <!--driver-->
 - <driverClassName>com.mysql.cj.jdbc.Driver</driverClassName>
 - <!--jdbc url-->
 - <jdbcUrl>jdbc:mysql://127.0.0.1:3306/test</jdbcUrl>
 - <!--生成文件類型-->
 - <fileType>HTML</fileType>
 - <!--文件輸出目錄-->
 - <fileOutputDir>/Users/lengleng</fileOutputDir>
 - <!--打開文件輸出目錄-->
 - <openOutputDir>false</openOutputDir>
 - <!--生成模板-->
 - <produceType>freemarker</produceType>
 - <!--描述-->
 - <description>數(shù)據(jù)庫文檔生成</description>
 - <!--版本-->
 - <version>${project.version}</version>
 - <!--標題-->
 - <title>數(shù)據(jù)庫文檔</title>
 - </configuration>
 - <executions>
 - <execution>
 - <phase>compile</phase>
 - <goals>
 - <goal>run</goal>
 - </goals>
 - </execution>
 - </executions>
 - </plugin>
 - </plugins>
 - </build>
 
責任編輯:華軒 
                    來源:
                    JAVA架構日記
 















 
 
 














 
 
 
 