t通过数据库逆向生成文档工具——screw

目录
一、pom.xml准备
二、工具类配置及生成
三、导出示例(html)
四、说明
目标
将数据库表字段分表生成表单,自动对应表字段以及注释,可导出为 html | doc | md 文件

一、pom.xml准备

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

二、工具类配置及生成

修改数据库连接信息,直接运行即可。
默认导出文件为html格式,导出到D盘,如果没有特殊的要求,其他的配置不用更改。

@Test
public  void contextLoads() {
    //数据源
    HikariConfig hikariConfig = new HikariConfig();
    hikariConfig.setDriverClassName("com.mysql.cj.jdbc.Driver");
    hikariConfig.setJdbcUrl("jdbc:mysql://localhost:3306/test?useUnicode=true&characterEncoding=UTF8&failOverReadOnly=false&zeroDateTimeBehavior=convertToNull&useSSL=false&serverTimezone=Asia/Shanghai");
    hikariConfig.setUsername("root");
    hikariConfig.setPassword("");
    //设置可以获取tables remarks信息
    hikariConfig.addDataSourceProperty("useInformationSchema", "true");
    hikariConfig.setMinimumIdle(2);
    hikariConfig.setMaximumPoolSize(5);
    DataSource dataSource = new HikariDataSource(hikariConfig);

    // 生成文件配置
    EngineConfig engineConfig = EngineConfig.builder()
            // 生成文件路径,自己mac本地的地址,这里需要自己更换下路径
            .fileOutputDir("D:\\temp")
            // 打开目录
            .openOutputDir(false)
            // 文件类型
            .fileType(EngineFileType.HTML)
            // 生成模板实现
            .produceType(EngineTemplateType.freemarker).build();

    // 生成文档配置(包含以下自定义版本号、描述等配置连接)
    Configuration config = Configuration.builder()
            .version("1.0.3")
            .description("生成文档信息描述")
            .dataSource(dataSource)
            .engineConfig(engineConfig)
            .produceConfig(getProcessConfig())
            .build();

    // 执行生成
    new DocumentationExecute(config).execute();
}


/**
 * 配置想要生成的表+ 配置想要忽略的表
 * @return 生成表配置
 */
public static ProcessConfig getProcessConfig(){
    // 忽略表名
    List<String> ignoreTableName = Arrays.asList("");
    // 忽略表前缀,如忽略a开头的数据库表
    List<String> ignorePrefix = Arrays.asList("a");
    // 忽略表后缀
    List<String> ignoreSuffix = Arrays.asList("_test","_czb");

    return ProcessConfig.builder()
            //根据名称指定表生成
            .designatedTableName(new ArrayList<>())
            //根据表前缀生成
            .designatedTablePrefix(new ArrayList<>())
            //根据表后缀生成
            .designatedTableSuffix(new ArrayList<>())
            //忽略表名
            .ignoreTableName(ignoreTableName)
            //忽略表前缀
            .ignoreTablePrefix(ignorePrefix)
            //忽略表后缀
            .ignoreTableSuffix(ignoreSuffix).build();
}

三、导出示例(html)

数据库设计文档

数据库名:test
文档版本:1.0.3
文档描述:生成文档信息描述

序号表名说明
1batch_job_execution_seq
2batch_job_instance
3batch_job_seq
4batch_step_execution_seq
5t_channel_file_notify渠道文件通知记录表
6t_contract_data合同数据表
7t_contract_file
8t_core_deal_data代偿赎回核心交易数据表
9t_core_deal_sum核心交易数据汇总表
10t_fee_subject费用科目表
11t_fee_type费用类型表
12t_fund_use_notify资金使用通知
13t_loan_subject_info科目信息
14t_mer_acct渠道商户账户表
15t_mer_acct_set渠道商户账户设置表
16t_pay_info支付信息表
17t_settle_data结算数据表
18t_settle_deal_data(代收 结清 对公)交易数据表
19t_settle_fee_type_data结算费用数据
20t_settle_order结算单表
21t_settle_rule结算规则表
22t_settle_rule_active结算待激活规则表
23t_settle_rule_history结算规则历史表
24t_settle_voucher结算凭证表
25t_settle_voucher_detail结算凭证明细表
26t_system_param系统参数表

返回目录表名:batch_job_execution_seq

说明:

数据列:

序号名称数据类型长度小数位允许空值主键默认值说明
1IDbigint190NN
2UNIQUE_KEYchar10NN

四、说明
数据库支持
MySQL、MariaDB、TIDB、Oracle、SqlServer、PostgreSQL、Cache DB
文件类型
  EngineFileType枚举类中提供三种类型:HTML、WORD、MD。
模板类型
  EngineTemplateType枚举类中提供两种类型:freemarker、velocity。
生成方式
  一种是代码生成,还有一种是通过Maven打包生成,私以为直接用工具类比较方便直接。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值