简介
在企业级开发中、我们经常会有编写数据库表结构文档的时间付出,从业以来,待过几家企业,关于数据库表结构文档状态:要么没有、要么有、但都是手写、后期运维开发,需要手动进行维护到文档中,很是繁琐、如果忘记一次维护、就会给以后工作造成很多困扰、无形中制造了很多坑留给自己和后人,于是需要一个插件工具screw[1]来维护。
screw 特点
支持数据库类型
依赖
这里以 mysql8 数据库为例子
- <!--数据库文档核心依赖-->
- <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() {
- //数据源
- 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)
- //生成模板实现
- .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("数据库设计文档生成")
- //数据源
- .dataSource(dataSource)
- //生成配置
- .engineConfig(engineConfig)
- //生成配置
- .produceConfig(processConfig).build();
- //执行生成
- 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>数据库文档生成</description>
- <!--版本-->
- <version>${project.version}</version>
- <!--标题-->
- <title>数据库文档</title>
- </configuration>
- <executions>
- <execution>
- <phase>compile</phase>
- <goals>
- <goal>run</goal>
- </goals>
- </execution>
- </executions>
- </plugin>
- </plugins>
- </build>
目录 读者基础 ?微服务架构梳理 https://www.coder4.com/homs_online/ ? ? 读者...
这5个PHP编程中的不良习惯,一定要改掉 PHP世界上最好的语言! 测试循环前数组是...
首先到这里下载其源码。里面东西挺多的,我们基本上可以把它放到两个文件夹就是...
MFC项目在vs2017编译正常无报错,但是升级vs2019后一打开项目就报如下错误。 项...
由于固态驱动器(SSD)的速度比传统的硬盘驱动器(HDD)快得多,并且价格越来越便宜...
本文实例为大家分享了javascript实现倒计时提示框的具体代码,供大家参考,具体...
本文实例为大家分享了vue实现按钮切换图片的具体代码,供大家参考,具体内容如下...
今天看到个不错的网页播放器,感觉不错,大家可以测试 我写的一个播放器网页: ...
目录 1. C语言文件接口(库函数) 1.1 fopen 1.2 fclose 1.3 fread 1.4 fwrite 1.5...
在大三的时候,一直就想搭建属于自己的一个博客,但由于各种原因,最终都不了了...