screw生成数据库文档

 以后只要数据库字段写的好,那么直接生成数据库字段表,样式还挺好看的。

下边的项目都是自己测试生成后的代码贴上来的。可以粘贴使用。

pom.xml
红色的就是主要的jar
<?xml version="1.0" encoding="UTF-8"?> <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd"> <modelVersion>4.0.0</modelVersion> <parent> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-parent</artifactId> <version>2.3.3.RELEASE</version> <relativePath/> <!-- lookup parent from repository --> </parent> <groupId>com.rjj</groupId> <artifactId>screw</artifactId> <version>0.0.1-SNAPSHOT</version> <name>screw</name> <description>Demo project for Spring Boot</description> <properties> <java.version>1.8</java.version> </properties> <dependencies> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-test</artifactId> <scope>test</scope> <exclusions> <exclusion> <groupId>org.junit.vintage</groupId> <artifactId>junit-vintage-engine</artifactId> </exclusion> </exclusions> </dependency> <dependency> <groupId>org.freemarker</groupId> <artifactId>freemarker</artifactId> <version>2.3.30</version> </dependency> <!-- screw核心 --> <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-jdbc</artifactId> </dependency> <!--mysql driver--> <dependency> <groupId>mysql</groupId> <artifactId>mysql-connector-java</artifactId> <version>8.0.20</version> </dependency> </dependencies> <build> <plugins> <plugin> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-maven-plugin</artifactId> </plugin> </plugins> </build> </project>
单元测试

package com.rjj.screw;

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 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.util.ArrayList;
import java.util.Arrays;
import java.util.List;

@SpringBootTest
class ScrewApplicationTests {

    @Autowired
    ApplicationContext applicationContext;
   @Autowired DataSource dataSource; @Test
void contextLoads() { //DataSource dataSource = (DataSource) applicationContext.getBean("dataSource"); // 生成文件配置 EngineConfig engineConfig = EngineConfig.builder() // 生成文件路径,自己mac本地的地址,这里需要自己更换下路径 .fileOutputDir("/Users/renjianjun/study/ideaWorkSpace/springboot-study-rjj/screw/doc") // 打开目录 .openOutputDir(false) // 文件类型 .fileType(EngineFileType.HTML) // 生成模板实现 .produceType(EngineTemplateType.freemarker).build(); // 生成文档配置(包含以下自定义版本号、描述等配置连接) Configuration config = Configuration.builder() .version("1.0.3") .title("rjj数据库") .description("生成文档信息描述") .dataSource(dataSource) .engineConfig(engineConfig) .produceConfig(getProcessConfig()) .build(); // 执行生成 new DocumentationExecute(config).execute(); } /** * 配置想要生成的表+ 配置想要忽略的表 * @return 生成表配置 */ public static ProcessConfig getProcessConfig(){ // 忽略表名,写到这里就不生成 List<String> ignoreTableName = Arrays.asList("scheduled_task","test_group"); // 忽略表前缀,如忽略a开头的数据库表,含有这个的就不生成 List<String> ignorePrefix = Arrays.asList("sys_","t"); // 忽略表后缀,含有的就不生成 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(); } }
原文地址:https://www.cnblogs.com/renjianjun/p/13585861.html