栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 软件开发 > 后端开发 > Java

数据库文档生成工具screw java方式

Java 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

数据库文档生成工具screw java方式

码云 https://gitee.com/leshalv/screw?_from=gitee_search
原理:使用freemarker,velocity模板工具,支持生成html,markdown,doc文档

1. yml配置
spring:
  datasource:
    type: com.zaxxer.hikari.HikariDataSource
    driverClassName: com.mysql.cj.jdbc.Driver
    url: jdbc:mysql://localhost:3306/springboot?serverTimezone=Asia/Shanghai&useSSL=false&zeroDateTimeBehavior=convertToNull&autoReconnect=true&characterEncoding=utf-8&allowMultiQueries=true
    username: root
    password: 123456
    hikari:
      maximum-pool-size: 10
      connection-timeout: 60000
      minimum-idle: 5
      idle-timeout: 500000
      max-lifetime: 540000
      connection-test-query: SELECT 1
2. pom依赖
 
        org.springframework.boot
        spring-boot-starter-parent
        2.3.4.RELEASE
        
    
 
      org.springframework.boot
      spring-boot-starter-web
  
  
      org.springframework.boot
      spring-boot-starter-freemarker
  

      org.mybatis.spring.boot
      mybatis-spring-boot-starter
      2.2.0
  
  
  
      com.github.pagehelper
      pagehelper-spring-boot-starter
      1.2.5
      
          
              mybatis-spring-boot-starter
              org.mybatis.spring.boot
          
      
  
  
      mysql
      mysql-connector-java
      runtime
   
 
    mysql
     mysql-connector-java
     runtime
                

    cn.smallbun.screw
    screw-core
    1.0.5
 
3. 测试
package com.yl.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 lombok.extern.slf4j.Slf4j;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.context.ApplicationContext;

import javax.sql.DataSource;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;
@Slf4j
@SpringBootTest
public class TestScrewDocumentGenerator {
    @Autowired
    DataSource dataSourceMysql;

	@Test
    public void documentGenerator() throws Exception {
        String database = dataSourceMysql.getConnection().getCatalog();
        //生成index.html目录
        generatorDocument( "D:/api/db/" + database, dataSourceMysql);
    }

private void generatorDocument(String fileOutputDir, DataSource dataSource) {
        // 配置生成方式
        EngineConfig engineConfig = EngineConfig.builder()
                // 生成文件路径
                .fileOutputDir(fileOutputDir)
                // 打开目录
                .openOutputDir(false)
                // 文件类型
                .fileType(EngineFileType.HTML)
                // 生成使用的模板
                .produceType(EngineTemplateType.freemarker)
                // 自定义文件名称
                .fileName("index")
                .build();
        // 配置忽略的表
        List ignoreTableName = new ArrayList<>();
//        ignoreTableName.add("test_user");
//        ignoreTableName.add("test_group");
        // 配置忽略指定前缀的表
        List ignoreTablePrefix = new ArrayList<>();
//        ignoreTablePrefix.add("test_");
        // 配置忽略指定后缀的表
        List ignoreTableSuffix = new ArrayList<>();
//        ignoreTableSuffix.add("_test");

        // 配置数据库表结构文档生成过程
        ProcessConfig processConfig = ProcessConfig.builder()
                
                // 生成指定名称的表
//                .designatedTableName(new ArrayList<>())
//                // 生成指定前缀的表
//                .designatedTablePrefix(new ArrayList<>())
                // 生成指定后缀的表
//                .designatedTableSuffix(new ArrayList<>())
                // 忽略指定名称的表
                .ignoreTableName(ignoreTableName)
                // 忽略指定前缀的表
                .ignoreTablePrefix(ignoreTablePrefix)
                // 忽略指定后缀的表
                .ignoreTableSuffix(ignoreTableSuffix)
                .build();

        // 文档生成信息配置
        Configuration config = Configuration.builder()
                // 文档版本
                .version("1.0.0")
                // 文档描述
                .description("数据库表结构文档")
                // 数据源
                .dataSource(dataSource)
                // 生成配置
                .engineConfig(engineConfig)
                // 执行配置
                .produceConfig(processConfig)
                .build();
        // 执行
        new DocumentationExecute(config).execute();
    }
}
转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/915051.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号