Screw导出数据库表信息

最为一名开发人员,平时的开发过程中自然少不了文档的编写工作,系统的设计文档,数据库的设计文档等,文档中往往需要我们描述数据库的表信息,手动维护起来麻烦而且容易错,今天推荐一款好用的工具用来导出数据库的表信息–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官方链接


版权声明:本文为sihuanghou原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接和本声明。