简介
在企业级开发中、咱们常常会有编写数据库表构造文档的工夫付出,从业以来,待过几家企业,对于数据库表构造文档状态:要么没有、要么有、但都是手写、前期运维开发,须要手动进行保护到文档中,很是繁琐、如果遗记一次保护、就会给当前工作造成很多困扰、无形中制作了很多坑留给本人和前人,于是须要一个插件工具 screw来保护。
screw 特点
- 简洁、轻量、设计良好。不须要 powerdesigner 这种分量的建模工具
- 多数据库反对 。反对市面常见的数据库类型 MySQL、Oracle、SqlServer
- 多种格局文档。反对 MD、HTML、WORD 格局
- 灵便扩大。反对用户自定义模板和展现款式
反对数据库类型
[✔️] MySQL
[✔️] MariaDB
[✔️] TIDB
[✔️] Oracle
[✔️] SqlServer
[✔️] PostgreSQL
[✔️] Cache DB
依赖
这里以 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. 通过自定义代码配置文档生成
@Testpublic 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>