practical! One click generation of database documents can be called swagger in the database industry

Time:2021-9-4

This article is included in the personal blog:www.chengxy-nds.top, technical data sharing and progress

Recently, the Department’s order business has been adjusted to close the order entry of other business lines and build a unified large order platform. It is necessary to sort out the data tables of each business line, but each business line library has nearly 100 tables related to orders, and the brain melon seeds are buzzing one by one.

In order not to repeat the CV operation, start with a glimmer of hopeGitHubLook in the and see if there are any tools to use. As a result, I really found the treasure,screw(screws), can actually generate database documents, excellent ~.
practical! One click generation of database documents can be called swagger in the database industry

1、 Database support

  • [x] MySQL
  • [x] MariaDB
  • [x] TIDB
  • [x] Oracle
  • [x] SqlServer
  • [x] PostgreSQL
  • [x] Cache DB

2、 Disposition

1. POM file

introducescrewCore package,HikariCPDatabase connection pool,HikariCPIt is known as the database connection pool with the best performance.

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

<!-- HikariCP -->
<dependency>
    <groupId>com.zaxxer</groupId>
    <artifactId>HikariCP</artifactId>
    <version>3.4.5</version>
</dependency>

<!--mysql driver-->
<dependency>
    <groupId>mysql</groupId>
    <artifactId>mysql-connector-java</artifactId>
    <version>8.0.20</version>
</dependency>

2. Configure data sources

Configuring data sources, settinguseInformationSchemaCan gettablesNote information.

spring.datasource.url=jdbc:mysql://45.93.1.5:3306/fire?useUnicode=true&characterEncoding=UTF-8&useSSL=false
spring.datasource.username=root
spring.datasource.password=123456
spring.datasource.driver-class-name=com.mysql.cj.jdbc.Driver
spring.datasource.xa.properties.useInformationSchema=true

3. Screen core configuration

screwThere are two modes of execution. The first ispomThe other is code execution.

<build>
    <plugins>
        <plugin>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-maven-plugin</artifactId>
        </plugin>
        <plugin>
            <groupId>cn.smallbun.screw</groupId>
            <artifactId>screw-maven-plugin</artifactId>
            <version>1.0.3</version>
            <dependencies>
                <!-- HikariCP -->
                <dependency>
                    <groupId>com.zaxxer</groupId>
                    <artifactId>HikariCP</artifactId>
                    <version>3.4.5</version>
                </dependency>
                <!--mysql driver-->
                <dependency>
                    <groupId>mysql</groupId>
                    <artifactId>mysql-connector-java</artifactId>
                    <version>8.0.20</version>
                </dependency>
            </dependencies>
            <configuration>
                <!--username-->
                <username>root</username>
                <!--password-->
                <password>123456</password>
                <!--driver-->
                <driverClassName>com.mysql.cj.jdbc.Driver</driverClassName>
                <!--jdbc url-->
                <jdbcUrl>jdbc:mysql://41.92.6.5:3306/fire</jdbcUrl>
                <!-- Generated file type -- >
                <fileType>HTML</fileType>
                <!-- Open file output directory -- >
                <openOutputDir>false</openOutputDir>
                <!-- Generate template -- >
                <produceType>freemarker</produceType>
                <!-- When the document name is empty, [database name - Description - version number] will be used as the document name -- >
                <!--< Docname > test document name < / docname > -- >
                <!-- Description -- >
                < description > database document generation < / description >
                <!-- Version -- >
                <version>${project.version}</version>
                <!-- Title -- >
                < title > fire database document < / Title >
            </configuration>
            <executions>
                <execution>
                    <phase>compile</phase>
                    <goals>
                        <goal>run</goal>
                    </goals>
                </execution>
            </executions>
        </plugin>
    </plugins>
</build>

After configurationmaven project->screwDouble click OK.
practical! One click generation of database documents can be called swagger in the database industry

Code generation is also very simple.

@SpringBootTest
public class ScrewApplicationTests {

    @Autowired
    ApplicationContext applicationContext;

    @Test
    void contextLoads() {
        DataSource dataSourceMysql = applicationContext.getBean(DataSource.class);
        //Generate file configuration
        EngineConfig engineConfig = EngineConfig.builder()
                //Generate the file path and the local MAC address. You need to change the path yourself
                .fileOutputDir("D:/")
                //Open Directory
                .openOutputDir(false)
                //File type
                .fileType(EngineFileType.HTML)
                //Generate template implementation
                .produceType(EngineTemplateType.freemarker).build();
        //Generate document configuration (including the following user-defined version number, description and other configuration connections)
        Configuration config = Configuration.builder()
                .version("1.0.3")
                . description ("generate document information description")
                .dataSource(dataSourceMysql)
                .engineConfig(engineConfig)
                .produceConfig(getProcessConfig())
                .build();
        //Execute build
        new DocumentationExecute(config).execute();
    }

    /**
     *Configure the table you want to generate + configure the table you want to ignore
     *
     *@ return generate table configuration
     */
    public static ProcessConfig getProcessConfig() {
        //Ignore table name
        List<String> ignoreTableName = Arrays.asList("a", "test_group");
        //Ignore table prefixes, such as database tables starting with a
        List<String> ignorePrefix = Arrays.asList("a", "t");
        //Ignore table suffix
        List<String> ignoreSuffix = Arrays.asList("_test", "czb_");
        return ProcessConfig.builder()
                //Specify table generation by name
                .designatedTableName(Arrays.asList("fire_user"))
                //Generated from table prefix
                .designatedTablePrefix(new ArrayList<>())
                //Generated from table suffix
                .designatedTableSuffix(new ArrayList<>())
                //Ignore table name
                .ignoreTableName(ignoreTableName)
                //Ignore table prefix
                .ignoreTablePrefix(ignorePrefix)
                //Ignore table suffix
                .ignoreTableSuffix(ignoreSuffix).build();
    }
}

4. Document format

screwyesHTMLDOCMDDocuments in three formats.

Modifications in code

.fileType(EngineFileType.HTML)

perhapspomfile

<fileType>MD</fileType>

DOCDocument style
practical! One click generation of database documents can be called swagger in the database industry
HTMLDocument style
practical! One click generation of database documents can be called swagger in the database industry
MDDocument style
practical! One click generation of database documents can be called swagger in the database industry
I have to say that this tool is really easy to use. It is a little proud and wooden to complete the task in advance!
practical! One click generation of database documents can be called swagger in the database industry

It’s not easy to be original. Burn your hair and output content. If you lose something, point a praise and encourage it!

Students who read VX in technical articles and want to get more Java resources can pay attention to my official account.Something inside the programmer, code:[666]