Screw(螺丝钉)是一款简洁好用的数据库表结构文档生成工具,支持maven 插件生成和代码生成了,支持MD、WORD、HTML三种格式文档
Screw最新依赖地址https://mvnrepository.com/artifact/cn.smallbun.screw/screw-core
生成效果图
代码生成使用教程:
1.导入数据库依赖
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-jdbc</artifactId>
</dependency>
<dependency>
<groupId>com.oracle.database.jdbc</groupId>
<artifactId>ojdbc8</artifactId>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<scope>runtime</scope>
</dependency>
2.导入Screw核心依赖
<dependency>
<groupId>cn.smallbun.screw</groupId>
<artifactId>screw-core</artifactId>
<version>1.0.5</version>
</dependency>
3.新建测试类,修改相关参数
package com.example.sqlfileutil;
import cn.smallbun.screw.core.Configuration;
import cn.smallbun.screw.core.engine.EngineConfig;
import cn.smallbun.screw.core.engine.EngineFileType;
import cn.smallbun.screw.core.engine.EngineTemplateType;
import cn.smallbun.screw.core.execute.DocumentationExecute;
import cn.smallbun.screw.core.process.ProcessConfig;
import com.zaxxer.hikari.HikariConfig;
import com.zaxxer.hikari.HikariDataSource;
import org.junit.jupiter.api.Test;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
public class Screw {
@Test
public void test() {
//DataSource dataSourceMysql = SpringContextUtil.getBean(DataSource.class);
HikariConfig hikariConfig = new HikariConfig();
/*hikariConfig.setDriverClassName("oracle.jdbc.OracleDriver");
hikariConfig.setJdbcUrl("jdbc:oracle:thin:@192.168.8.104:1521/orcl");
hikariConfig.setUsername("C##V13");
hikariConfig.setPassword("oracle");
HikariDataSource dataSourceMysql = new HikariDataSource(hikariConfig);
*/
hikariConfig.setDriverClassName("com.mysql.jdbc.Driver");
hikariConfig.setJdbcUrl("jdbc:mysql://127.0.0.1:3306/anychat_manage");
hikariConfig.setUsername("root");
hikariConfig.setPassword("123456");
HikariDataSource dataSourceMysql = new HikariDataSource(hikariConfig);
// 生成文件配置
EngineConfig engineConfig = EngineConfig.builder()
// 生成文件路径
.fileOutputDir("D:/sqlFile/ProductExperienceCenter")
// 打开目录
.openOutputDir(true)
// 文件类型
.fileType(EngineFileType.HTML)
// 生成模板实现
.produceType(EngineTemplateType.freemarker).build();
// 生成文档配置(包含以下自定义版本号、描述等配置连接)
Configuration config = Configuration.builder()
.version("V1.0")
.title("产品体验中心数据库文档")
.description("产品体验中心数据库文档信息描述")
.dataSource(dataSourceMysql)
.engineConfig(engineConfig)
.produceConfig(getProcessConfig())
.build();
// 执行生成
new DocumentationExecute(config).execute();
}
/**
* 配置想要生成的表+ 配置想要忽略的表
*
* @return 生成表配置
*/
public static ProcessConfig getProcessConfig() {
// 忽略表名dept,dept1
List<String> ignoreTableName = Arrays.asList("dept", "dept1");
// 忽略表前缀,如忽略dept开头的数据库表
List<String> ignorePrefix = Arrays.asList("dept", "dept1");
// 忽略表后缀dept,dept1
List<String> ignoreSuffix = Arrays.asList("dept", "dept1");
return ProcessConfig.builder()
//根据名称指定表生成
// .designatedTableName(Arrays.asList("BASE_ACCOUNTCTRL", "BASE_APPCONFIG","BASE_APPTYPE","BASE_DATALIMIT","BASE_MODULE","BASE_ORGANIZE","BASE_PERMISSION","BASE_PERMISSIONTYPE","BASE_RESOURCECATEGORY","BASE_RESOURCEPERMISSION","BASE_RESOURCEPERMISSIONLIMIT","BASE_RESOURCEPERMISSIONSCOPE","BASE_RESOURCEREQDEF","BASE_RESOURCEREQLOG","BASE_ROLE","BASE_ROLECATEGORY","BASE_ROLEUSER","BASE_USER","BASE_VERSION","BASE_VERSIONRELATION","SYSTEMCONFIG"))
.designatedTableName(Arrays.asList("file_relation"))
//根据表前缀生成
.designatedTablePrefix(Arrays.asList("product"))
//根据表后缀生成
.designatedTableSuffix(new ArrayList<>())
//忽略表名
.ignoreTableName(ignoreTableName)
//忽略表前缀
.ignoreTablePrefix(ignorePrefix)
//忽略表后缀
.ignoreTableSuffix(ignoreSuffix).build();
}
}