screw 一个简洁好用的数据库表结构文档生成工具

编程入门 行业动态 更新时间:2024-10-23 15:24:29

screw 一个简洁<a href=https://www.elefans.com/category/jswz/34/1769705.html style=好用的数据库表结构文档生成工具"/>

screw 一个简洁好用的数据库表结构文档生成工具

目录

一:基本概念

名称由来:

特点:  

数据库支持

文档生成支持类型

二:使用操作

方式一:普通方式

        ①:准备一个基本的maven项目

        ②:引入依赖

方式二:Maven 插件

       在添加以上的依赖之后,再添加以下代码即可

三:总结


一:基本概念

     在企业级开发中、我们经常会有编写数据库表结构文档的时间付出,从业以来,待过几家企业,关于数据库表结构文档状态:要么没有、要么有、但都是手写、后期运维开发,需要手动进行维护到文档中,很是繁琐、如果忘记一次维护、就会给以后工作造成很多困扰、无形中制造了很多坑留给自己和后人,就对于这个问题,有一位程序猿大佬以此设置了一个开源的插件工具,来解决这些问题,并造福大家

    

  • 名称由来:

           从小就学过雷锋的螺丝钉精神,摘自雷锋日记:虽然是细小的螺丝钉,是个细微的小齿轮,然而如果缺了它,那整个的机器就无法运转了,慢说是缺了它,即使是一枚小螺丝钉没拧紧,一个小齿轮略有破损,也要使机器的运转发生故障的,这个工具,很有这意味,虽然很小、但是开发中缺了它还不行,于是便起名为screw(螺丝钉)

 

  • 特点:  

  1. 简洁、轻量、设计良好

  2. 多数据库支持

  3. 多种格式文档

  4. 灵活扩展

  5. 支持自定义模板

  • 数据库支持

  1. MySQL
  2. MariaDB
  3. TIDB
  4. Oracle
  5. SqlServer
  6. PostgreSQL


  • 文档生成支持类型

  1. html
  2. word
  3. markdown

二:使用操作

  • 方式一:普通方式

        ①:准备一个基本的maven项目

        ②:引入依赖

 <!-- screw核心 --><dependency><groupId>cn.smallbun.screw</groupId><artifactId>screw-core</artifactId><version>1.0.4</version></dependency>

    ps:由于我在这里使用的是mysql数据库,所以还需要mysql的依赖

 <!--mysql driver--><dependency><groupId>mysql</groupId><artifactId>mysql-connector-java</artifactId><version>8.0.20</version></dependency></dependencies>

   注意:普通方式实现需要引入以下依赖,方便测试代码中的方法功能可以实现

<dependency><groupId>com.zaxxer</groupId><artifactId>HikariCP</artifactId><version>3.4.5</version></dependency>

             HikariCP 是一个高性能的 JDBC 连接池组件,号称性能最好的后起之秀,是一个基于BoneCP做了不少的改进和优化的高性能JDBC连接池。

完整pom.xml文件代码如下:

<?xml version="1.0" encoding="UTF-8"?><project xmlns=".0.0" xmlns:xsi=""xsi:schemaLocation=".0.0 .0.0.xsd"><modelVersion>4.0.0</modelVersion><groupId>com.tangyuan</groupId><artifactId>code-generator</artifactId><version>1.0-SNAPSHOT</version><packaging>war</packaging><name>code-generator Maven Webapp</name><!-- FIXME change it to the project's website --><url>;/url><properties><project.build.sourceEncoding>UTF-8</project.build.sourceEncoding><mavenpiler.source>1.8</mavenpiler.source><mavenpiler.target>1.8</mavenpiler.target><tomcat.version>8.5</tomcat.version></properties><dependencies><dependency><groupId>junit</groupId><artifactId>junit</artifactId><version>4.11</version><scope>test</scope></dependency><!-- screw核心 --><dependency><groupId>cn.smallbun.screw</groupId><artifactId>screw-core</artifactId><version>1.0.4</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></dependencies><build><plugins><plugin><groupId>org.apache.maven.plugins</groupId><artifactId>maven-clean-plugin</artifactId><version>3.0.0</version></plugin><plugin><groupId>cn.smallbun.screw</groupId><artifactId>screw-maven-plugin</artifactId><version>1.0.4</version><dependencies><!--HikariCP--><dependency><groupId>com.zaxxer</groupId><artifactId>HikariCP</artifactId><version>3.4.5</version></dependency><!--  mysql driver&ndash;&gt;--><dependency><groupId>mysql</groupId><artifactId>mysql-connector-java</artifactId><version>8.0.20</version></dependency><dependency><groupId>cn.smallbun.screw</groupId><artifactId>screw-core</artifactId><version>1.0.4</version></dependency></dependencies></plugin></plugins></build>
</project>

    ③:编写一个测试代码,并设置好主程序入口

package test;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 javax.sql.DataSource;
import java.util.ArrayList;/*** @author 唐渊* @create  2022-08-01 11:38*/
public class test {public static void main(String[] args) {//数据源HikariConfig hikariConfig = new HikariConfig();hikariConfig.setDriverClassName("com.mysql.cj.jdbc.Driver");hikariConfig.setJdbcUrl("jdbc:mysql://127.0.0.1:3306/medical?serverTimezone=GMT%2B8");hikariConfig.setUsername("root");hikariConfig.setPassword("1234");//设置可以获取tables remarks信息hikariConfig.addDataSourceProperty("useInformationSchema", "true");hikariConfig.setMinimumIdle(2);hikariConfig.setMaximumPoolSize(5);DataSource dataSource = new HikariDataSource(hikariConfig);//生成配置EngineConfig engineConfig = EngineConfig.builder()//生成文件路径.fileOutputDir("C:\\Users\\Administrator\\Desktop\\数据表文档\\")//数据导出的地址//打开目录.openOutputDir(true)//文件类型// .fileType(EngineFileType.HTML)//.fileType(EngineFileType.WORD).fileType(EngineFileType.MD)//生成模板实现.produceType(EngineTemplateType.freemarker).build();//自定义文件名称//.fileName("自定义文件名称").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()//指定生成逻辑、当存在指定表、指定表前缀、指定表后缀时,将生成指定表,其余表不生成、并跳过忽略表配置//根据名称指定表生成.designatedTableName(new ArrayList<>())//根据表前缀生成.designatedTablePrefix(new ArrayList<>())//根据表后缀生成.designatedTableSuffix(new ArrayList<>())//忽略表名.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();}/**ps:* java.sql.SQLException: The server time zone value* 是由于我们默认的时区比东八区少了八个小时。* 在使用的项目中,设计到数据库的信息时,在url中 加入:?serverTimezone=GMT%2B8*//*** screw - Exception during pool initialization.*/
}

   

测试结果:

  • html类型

  • word类型

 

  • markdwon类型

  • 方式二:Maven 插件

       在添加以上的依赖之后,再添加以下代码即可

<!--方式二:Maven插件--><build><plugins><plugin><groupId>cn.smallbun.screw</groupId><artifactId>screw-maven-plugin</artifactId><version>1.0.4</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>1234</password><!--driver--><driverClassName>com.mysql.cj.jdbc.Driver</driverClassName><!--jdbc url--><jdbcUrl>jdbc:mysql://127.0.0.1:3306/db_shopping?serverTimezone=GMT%2B8</jdbcUrl><!--生成文件类型 HTML  MD WORD--><fileType>WORD</fileType><!--打开文件输出目录--><openOutputDir>false</openOutputDir><!--生成模板--><produceType>freemarker</produceType><!--文档名称 为空时:将采用[数据库名称-描述-版本号]作为文档名称--><fileName></fileName><!--描述--><description>数据库文档生成</description><!--版本--><version>${project.version}</version><!--标题--><title>数据库文档</title></configuration><executions><execution><phase>compile</phase><goals><goal>run</goal></goals></execution></executions></plugin></plugins></build>

          与普通方式不同,maven插件的运行方式是不相同的,运行方式如下:

 

 

           可以点击,在当前面板查看,也可以找到项目的存放文件,进行查看

三:总结

        screw是一个不错的插件,可以很轻松的解决数据库表结构文档文件,各位大佬如果有兴趣的话,可以阅读阅读探索探索,欢迎各位大佬前来斧正

    

 

更多推荐

screw 一个简洁好用的数据库表结构文档生成工具

本文发布于:2024-02-06 17:42:31,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1751057.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:好用   简洁   结构   文档   数据库

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!