亚洲视频二区_亚洲欧洲日本天天堂在线观看_日韩一区二区在线观看_中文字幕不卡一区

公告:魔扣目錄網為廣大站長提供免費收錄網站服務,提交前請做好本站友鏈:【 網站目錄:http://www.430618.com 】, 免友鏈快審服務(50元/站),

點擊這里在線咨詢客服
新站提交
  • 網站:51998
  • 待審:31
  • 小程序:12
  • 文章:1030137
  • 會員:747

數據庫界的swagger,連接數據庫直接生成數據庫文檔

 

一、數據庫支持

  • MySQL
  • MariaDB
  • TIDB
  • Oracle
  • SqlServer
  • PostgreSQL
  • Cache DB

二、配置

1、pom文件

引入screw核心包,HikariCP數據庫連接池,HikariCP號稱性能最出色的數據庫連接池。

<!-- screw核心 -->
<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、配置數據源

配置數據源,設置 useInformationSchema 可以獲取tables注釋信息。

spring.datasource.url=jdbc:mysql://192.168.1.5:3306/test?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、screw 核心配置

screw有兩種執行方式,第一種是pom文件配置,另一種是代碼執行。

<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://192.168.1.5:3306/test</jdbcUrl>
                <!--生成文件類型-->
                <fileType>html</fileType>
                <!--打開文件輸出目錄-->
                <openOutputDir>false</openOutputDir>
                <!--生成模板-->
                <produceType>freemarker</produceType>
                <!--文檔名稱 為空時:將采用[數據庫名稱-描述-版本號]作為文檔名稱-->
                <!--<docName>測試文檔名稱</docName>-->
                <!--描述-->
                <description>數據庫文檔生成</description>
                <!--版本-->
                <version>${project.version}</version>
                <!--標題-->
                <title>fire數據庫文檔</title>
            </configuration>
            <executions>
                <execution>
                    <phase>compile</phase>
                    <goals>
                        <goal>run</goal>
                    </goals>
                </execution>
            </executions>
        </plugin>
    </plugins>
</build>

配置完以后,在 maven project->screw 雙擊執行ok。

數據庫界的swagger,連接數據庫直接生成數據庫文檔

pom執行方式

代碼生成方式

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.Eng.NETemplateType;
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;

   @Test
   void contextLoads() {
      DataSource dataSourceMysql = applicationContext.getBean(DataSource.class);

      // 生成文件配置
      EngineConfig engineConfig = EngineConfig.builder()
            // 生成文件路徑,自己mac本地的地址,這里需要自己更換下路徑
            .fileOutputDir("/Users/mac/Desktop")
            // 打開目錄
            .openOutputDir(false)
            // 文件類型
            .fileType(EngineFileType.HTML)
            // 生成模板實現
            .produceType(EngineTemplateType.freemarker).build();

      // 生成文檔配置(包含以下自定義版本號、描述等配置連接)
      Configuration config = Configuration.builder()
            .version("1.0.3")
            .description("生成文檔信息描述")
            .dataSource(dataSourceMysql)
            .engineConfig(engineConfig)
            .produceConfig(getProcessConfig())
            .build();

      // 執行生成
      new DocumentationExecute(config).execute();
   }


   /**
    * 配置想要生成的表+ 配置想要忽略的表
    * @return 生成表配置
    */
   public static ProcessConfig getProcessConfig(){
      // 忽略表名
      List<String> ignoreTableName = Arrays.asList("aa","test_group");
      // 忽略表前綴,如忽略a開頭的數據庫表
      List<String> ignorePrefix = Arrays.asList("a","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();
   }
}

4、文檔格式

screw 有 HTML、DOC、MD 三種格式的文檔。

代碼中的修改

.fileType(EngineFileType.HTML)

或者pom文件

<fileType>MD</fileType>

 

數據庫界的swagger,連接數據庫直接生成數據庫文檔

數據庫文檔

5、鏈接

文檔工具 screw:https://gitee.com/leshalv/screw

分享到:
標簽:數據庫
用戶無頭像

網友整理

注冊時間:

網站:5 個   小程序:0 個  文章:12 篇

  • 51998

    網站

  • 12

    小程序

  • 1030137

    文章

  • 747

    會員

趕快注冊賬號,推廣您的網站吧!
最新入駐小程序

數獨大挑戰2018-06-03

數獨一種數學游戲,玩家需要根據9

答題星2018-06-03

您可以通過答題星輕松地創建試卷

全階人生考試2018-06-03

各種考試題,題庫,初中,高中,大學四六

運動步數有氧達人2018-06-03

記錄運動步數,積累氧氣值。還可偷

每日養生app2018-06-03

每日養生,天天健康

體育訓練成績評定2018-06-03

通用課目體育訓練成績評定