1、简介

在企业级开发中、咱们常常会有编写数据库表构造文档的工夫付出,从业以来,待过几家企业,对于数据库表构造文档状态:要么没有、要么有、但都是手写、前期运维开发,须要手动进行保护到文档中,很是繁琐、如果遗记一次保护、就会给当前工作造成很多困扰、无形中制作了很多坑留给本人和前人,于是萌发了要本人写一个插件工具的想法

2、特点

  • 简洁、轻量、设计良好
  • 多数据库反对
  • 多种格局文档
  • 灵便扩大
  • 反对自定义模板

3、数据库反对

  • [x] MySQL
  • [x] MariaDB
  • [x] TIDB
  • [x] Oracle
  • [x] SqlServer
  • [x] PostgreSQL
  • [x] Cache DB(2016)
  • [ ] H2 (开发中)
  • [ ] DB2 (开发中)
  • [ ] HSQL (开发中)
  • [ ] SQLite(开发中)
  • [ ] 瀚高(开发中)
  • [ ] 达梦 (开发中)
  • [ ] 虚谷 (开发中)
  • [ ] 人大金仓(开发中)

4、文档生成反对

  • [x] html
  • [x] word
  • [x] markdown

5、文档截图

html

word

markdwon

6、应用形式

一般形式

  • 引入依赖
<dependency>    <groupId>cn.smallbun.screw</groupId>    <artifactId>screw-core</artifactId>    <version>${lastVersion}</version> </dependency>
  • 编写代码
/** * 文档生成 */void documentGeneration() {   //数据源   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);   //生成配置   EngineConfig engineConfig = EngineConfig.builder()         //生成文件门路         .fileOutputDir(fileOutputDir)         //关上目录         .openOutputDir(true)         //文件类型         .fileType(EngineFileType.HTML)         //生成模板实现         .produceType(EngineTemplateType.freemarker)         //自定义文件名称         .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();}

Maven 插件

<build>    <plugins>        <plugin>            <groupId>cn.smallbun.screw</groupId>            <artifactId>screw-maven-plugin</artifactId>            <version>${lastVersion}</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>password</password>                <!--driver-->                <driverClassName>com.mysql.cj.jdbc.Driver</driverClassName>                <!--jdbc url-->                <jdbcUrl>jdbc:mysql://127.0.0.1:3306/xxxx</jdbcUrl>                <!--生成文件类型-->                <fileType>HTML</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>

7、扩大模块

pojo生成性能

  • 性能简介

pojo生成性能是基于screw延长出的扩大模块,目前处于初步开发的状态。在日常的开发中,通过需要剖析、建模之后,往往会先在数据库中建表,其次在进行代码的开发。

那么pojo生成性能在这个阶段就能够帮忙大家节俭一些重复劳动了。应用pojo生成性能能够间接依据数据库生成对应的java pojo对象。这样后续的批改,开发都会很不便。

  • 数据库反对

[x] MySQL

  • 应用形式

引入依赖

<dependency>    <groupId>cn.smallbun.screw</groupId>    <artifactId>screw-extension</artifactId>    <version>${lastVersion}</version></dependency>

编写代码

/** * pojo生成 */void pojoGeneration() {    //数据源    HikariConfig hikariConfig = new HikariConfig();    hikariConfig.setDriverClassName("com.mysql.cj.jdbc.Driver");    hikariConfig.setJdbcUrl("jdbc:mysql://127.0.0.1:3306/screw");    hikariConfig.setUsername("screw");    hikariConfig.setPassword("screw");    //设置能够获取tables remarks信息    hikariConfig.addDataSourceProperty("useInformationSchema", "true");    hikariConfig.setMinimumIdle(2);    hikariConfig.setMaximumPoolSize(5);    DataSource dataSource = new HikariDataSource(hikariConfig);    ProcessConfig processConfig = ProcessConfig.builder()        //指定生成逻辑、当存在指定表、指定表前缀、指定表后缀时,将生成指定表,其余表不生成、并跳过疏忽表配置        //依据名称指定表生成        .designatedTableName(new ArrayList<>())        //依据表前缀生成        .designatedTablePrefix(new ArrayList<>())        //依据表后缀生成        .designatedTableSuffix(new ArrayList<>()).build();    //设置生成pojo相干配置    PojoConfiguration config = new PojoConfiguration();    //设置文件寄存门路    config.setPath("/cn/smallbun/screw/");    //设置包名    config.setPackageName("cn.smallbun.screw");    //设置是否应用lombok    config.setUseLombok(false);    //设置数据源    config.setDataSource(dataSource);    //设置命名策略    config.setNameStrategy(new HumpNameStrategy());    //设置表过滤逻辑    config.setProcessConfig(processConfig);    //执行生成    new PojoExecute(config).execute();}

8、常见问题

  • 生成后文档乱码?

MySQL:URL退出?characterEncoding=UTF-8。

  • Caused by: java.lang.NoSuchFieldError: VERSION_2_3_30?

查看我的项目freemarker依赖,这是因为版本过低造成的,降级版本为2.3.30即可。

  • java.lang.AbstractMethodError: oracle.jdbc.driver.T4CConnection.getSchema()Ljava/lang/String;

这是因为oracle驱动版本过低造成的,删除或屏蔽目前驱动版本,驱动增加降级为以下版本:

<dependency>   <groupId>com.oracle.ojdbc</groupId>   <artifactId>ojdbc8</artifactId>   <version>19.3.0.0</version></dependency><dependency>   <groupId>cn.easyproject</groupId>   <artifactId>orai18n</artifactId>   <version>12.1.0.2.0</version></dependency>
  • MySQL数据库表和列字段有阐明、生成文档没有阐明?

URL链接退出useInformationSchema=true即可。

  • java.lang.AbstractMethodError: com.mysql.jdbc.JDBC4Connection.getSchema()Ljava/lang/String;

这是因为mysql驱动版本过低造成的,降级mysql驱动版本为最新即可。

我的项目地址:https://gitee.com/leshalv/screw

近期热文举荐:

1.1,000+ 道 Java面试题及答案整顿(2022最新版)

2.劲爆!Java 协程要来了。。。

3.Spring Boot 2.x 教程,太全了!

4.别再写满屏的爆爆爆炸类了,试试装璜器模式,这才是优雅的形式!!

5.《Java开发手册(嵩山版)》最新公布,速速下载!

感觉不错,别忘了顺手点赞+转发哦!