Cut to the chase

Today’s hero is SCREW

First of all, of course, is the first to create a project I side directly created is the boot project, of course, maven project can also then import database dependency and today's protagonist SCREWCopy the code
     <dependency>
                <groupId>mysql</groupId>
                <artifactId>mysql-connector-java</artifactId>
                <version>8.022.</version> </dependency> <! --> <dependency> <groupId>com.zaxxer</groupId> <artifactId>HikariCP</artifactId> <version>3.4. 5</version>
            </dependency>  
             <dependency>
                <groupId>cn.smallbun.screw</groupId>
                <artifactId>screw-core</artifactId>
                <version>1.0. 5</version>
            </dependency> 
Copy the code
  • Creating a startup class
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 com.zaxxer.hikari.HikariConfig;
import com.zaxxer.hikari.HikariDataSource;

import javax.sql.DataSource;
import java.util.Arrays;
import java.util.Collections;

public class ScrewMain {
 
    private static final String DB_URL = "jdbc:mysql://localhost:3306"; // Database link
    private static final String DB_NAME = "shop";  // Database name
    private static final String DB_USERNAME = "root";  / / account
    private static final String DB_PASSWORD = "000000";  / / password
    private static final String FILE_OUTPUT_DIR = "F: \ \ data"; // Generate position
    private static final EngineFileType FILE_OUTPUT_TYPE = EngineFileType.HTML; // You can set Word or Markdown format
    private static final String DOC_FILE_NAME = "Mysql Database Documentation";
    private static final String DOC_VERSION = "1.0.0";
    private static final String DOC_DESCRIPTION = "Shop Document Description";
 
    public static void main(String[] args) {
        // Create screw configuration
        Configuration config = Configuration.builder()
                .version(DOC_VERSION)  / / version
                .description(DOC_DESCRIPTION) / / description
                .dataSource(buildDataSource()) / / the data source
                .engineConfig(buildEngineConfig()) // Engine configuration
                .produceConfig(buildProcessConfig()) // Process the configuration
                .build();
 
        // Execute SCREW to generate database document
        new DocumentationExecute(config).execute();
    }
 
    /** * Create data source */
    private static DataSource buildDataSource(a) {
        // Create the HikariConfig configuration class
        HikariConfig hikariConfig = new HikariConfig();
        hikariConfig.setDriverClassName("com.mysql.cj.jdbc.Driver"); // Database driver
        hikariConfig.setJdbcUrl(DB_URL + "/" + DB_NAME+"? serverTimezone=UTC");
        hikariConfig.setUsername(DB_USERNAME);
        hikariConfig.setPassword(DB_PASSWORD);
        hikariConfig.addDataSourceProperty("useInformationSchema"."true"); // Set to get tables Remarks
        // Create a data source
        return new HikariDataSource(hikariConfig);
    }
 
    /** * Create screw's engine configuration */
    private static EngineConfig buildEngineConfig(a) {
        return EngineConfig.builder()
                .fileOutputDir(FILE_OUTPUT_DIR) // Generate file path
                .openOutputDir(false) // Open the directory
                .fileType(FILE_OUTPUT_TYPE) // File type
                .produceType(EngineTemplateType.freemarker) // File type
                .fileName(DOC_FILE_NAME) // Customize the file name
                .build();
    }
 
    /** * create screw processing configuration, generally can ignore * specified generation logic, when there is a specified table, a specified table prefix, a specified table suffix, will generate a specified table, the rest of the table is not generated, and skip ignore table configuration */
    private static ProcessConfig buildProcessConfig(a) {
        return ProcessConfig.builder()
                .designatedTableName(Collections.<String>emptyList())  // Specify table generation by name
                .designatedTablePrefix(Collections.<String>emptyList()) // Based on the table prefix
                .designatedTableSuffix(Collections.<String>emptyList()) // Based on the table suffix
                .ignoreTableName(Arrays.asList("test_user"."test_group")) // Ignore the table name
                .ignoreTablePrefix(Collections.singletonList("test_")) // Ignore the table prefix
                .ignoreTableSuffix(Collections.singletonList("_test")) // Ignore the table suffix.build(); }}Copy the code