资讯动态

数据库文档生成工具 screw

发布时间:2026/10/17 7:26:50 来源:尧图企业网站定制
一、前言在企业级开发中、我们经常会有编写数据库表结构文档的时间付出。现在大多项目关于数据库表结构文档状态要么没有、要么有、但都是手写、后期运维开发需要手动进行维护到文档中很是繁琐、如果忘记一次维护、就会给以后工作造成很多困扰、无形中制造了很多坑留给自己和后人。所以screw就应运而生。本文主要以使用为主项目基础为springboot。目前已经支持的数据如下MySQLMariaDBTIDBOracleSqlServerPostgreSQLCache DB2016二、使用首先搭建一个springboot基础项目2.1 依赖引入dependencygroupIdcn.smallbun.screw/groupIdartifactIdscrew-core/artifactIdversion1.0.5/version/dependencydependencygroupIdorg.springframework.boot/groupIdartifactIdspring-boot-starter-jdbc/artifactId/dependencydependencygroupIdmysql/groupIdartifactIdmysql-connector-java/artifactIdscoperuntime/scope/dependency2.2 配置数据源这里演示使用了默认数据源如果需要单独生成也可以在生成方法中进行配置。application.yml文件如下spring:datasource:driver-class-name:com.mysql.cj.jdbc.Driverurl:jdbc:mysql://127.0.0.1:3306/springboot?useUnicodetruecharacterEncodingutf8serverTimezoneUTCallowMultiQueriestrueuseSSLfalseusername:springpassword:spring#1232.3 创建DocumentServerDocumentServer.javaServicepublicclassDocumentServer{AutowiredDataSourcedataSource;/** * 文档生成 */publicvoiddocumentGeneration(){/*//数据源 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); */StringfileDirE:\\workspace\\workspace(idea)\\spring\\boot\\42springboot-screw\\src\\main\\resources\\doc;//生成配置EngineConfigengineConfigEngineConfig.builder()//生成文件路径.fileOutputDir(fileDir)//打开目录.openOutputDir(true)//文件类型.fileType(EngineFileType.MD)//生成模板实现.produceType(EngineTemplateType.freemarker)//自定义文件名称.fileName(自定义文件名称).build();//忽略表ArrayListStringignoreTableNamenewArrayList();ignoreTableName.add(test_user);ignoreTableName.add(test_group);//忽略表前缀ArrayListStringignorePrefixnewArrayList();ignorePrefix.add(test_);//忽略表后缀ArrayListStringignoreSuffixnewArrayList();ignoreSuffix.add(_test);ProcessConfigprocessConfigProcessConfig.builder()//指定生成逻辑、当存在指定表、指定表前缀、指定表后缀时将生成指定表其余表不生成、并跳过忽略表配置//根据名称指定表生成.designatedTableName(newArrayList())//根据表前缀生成.designatedTablePrefix(newArrayList())//根据表后缀生成.designatedTableSuffix(newArrayList())//忽略表名.ignoreTableName(ignoreTableName)//忽略表前缀.ignoreTablePrefix(ignorePrefix)//忽略表后缀.ignoreTableSuffix(ignoreSuffix).build();//配置ConfigurationconfigConfiguration.builder()//版本.version(1.0.0)//描述.description(数据库设计文档生成)//数据源.dataSource(dataSource)//生成配置.engineConfig(engineConfig)//生成配置.produceConfig(processConfig).build();//执行生成newDocumentationExecute(config).execute();}}2.4 测试编写测试类AutowiredDocumentServerdocumentServer;Testpublicvoidtest(){documentServer.documentGeneration();}我们分别修改文件类型fileType分别设置为 EngineFileType.MD、EngineFileType.WORLD、EngineFileType.HTML测试生成文件如下生成内容如下wordhtmlmarkdown

读完文章,也想定制专属网站?

尧图设计师 24 小时内与您沟通定制方案

免费获取报价 →
↑