Screw导出数据库表信息

4 篇文章 0 订阅
2 篇文章 0 订阅

最为一名开发人员,平时的开发过程中自然少不了文档的编写工作,系统的设计文档,数据库的设计文档等,文档中往往需要我们描述数据库的表信息,手动维护起来麻烦而且容易错,今天推荐一款好用的工具用来导出数据库的表信息–Screw。
在这里插入图片描述

springboot集成Screw

1、引入依赖

<dependency>
      <groupId>org.springframework.boot</groupId>
      <artifactId>spring-boot-starter-jdbc</artifactId>
    </dependency>
    <dependency>
      <groupId>org.springframework.boot</groupId>
      <artifactId>spring-boot-starter-web</artifactId>
    </dependency>
    <dependency>
      <groupId>mysql</groupId>
      <artifactId>mysql-connector-java</artifactId>
      <scope>runtime</scope>
    </dependency>
    <dependency>
      <groupId>cn.smallbun.screw</groupId>
      <artifactId>screw-core</artifactId>
      <version>1.0.3</version>
    </dependency>
    <dependency>
      <groupId>org.springframework.boot</groupId>
      <artifactId>spring-boot-starter-test</artifactId>
      <scope>test</scope>
    </dependency>

2、数据库配置

spring.datasource.url=jdbc:mysql://xxxx:3306/test?useUnicode=true&characterEncoding=UTF-8&useSSL=false
spring.datasource.username=root
spring.datasource.password=xxxx
spring.datasource.driver-class-name=com.mysql.cj.jdbc.Driver
#按照码云文档说明: MySQL数据库表和列字段有说明、生成文档没有说明
spring.datasource.xa.properties.userInformationSchema= true

3、编写代码

@Component
public class DatabaseDownload implements ApplicationRunner {

  @Autowired
  private ApplicationContext applicationContext;

  @Override
  public void run(ApplicationArguments args) throws Exception {
    DataSource dataSource = applicationContext.getBean(DataSource.class);
    EngineConfig engineConfig = EngineConfig.builder()
        //这只文档的输出路径
        .fileOutputDir("/resources")
        .openOutputDir(true)
        //设置导出的文档类型
        .fileType(EngineFileType.WORD)
        .produceType(EngineTemplateType.freemarker)
        .build();
    Configuration configuration = Configuration.builder()
        .version("1.0")
        .description("测试数据库")
        .dataSource(dataSource)
        .engineConfig(engineConfig)
        .produceConfig(getProcessConfig())
        .build();
    new DocumentationExecute(configuration).execute();
  }

  private ProcessConfig getProcessConfig(){
    return ProcessConfig.builder()
        .designatedTableName(new ArrayList<>())
        .designatedTablePrefix(new ArrayList<>())
        .designatedTableSuffix(new ArrayList<>())
        .build();

  }
}

后记

感谢作者的开源,附上原版链接 Screw官方链接

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值