最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

SpringBoot集成screw實現(xiàn)數(shù)據(jù)庫表結(jié)構(gòu)文檔生成

 更新時間:2025年07月29日 09:47:19   作者:程序猿羊  
screw(螺絲釘)是一款簡潔好用的數(shù)據(jù)庫表結(jié)構(gòu)文檔生成工具,而在日常的開發(fā)工作中在某些場景可能會需要數(shù)據(jù)庫表結(jié)構(gòu)的文檔,下面我們就來看看SpringBoot如何集成screw實現(xiàn)數(shù)據(jù)庫表結(jié)構(gòu)文檔生成吧

一、簡介

日常的開發(fā)工作中,經(jīng)常會和數(shù)據(jù)庫打交道,在某些場景可能會需要數(shù)據(jù)庫表結(jié)構(gòu)的文檔,  screw(螺絲釘)是一款簡潔好用的數(shù)據(jù)庫表結(jié)構(gòu)文檔生成工具。支持多數(shù)據(jù)庫、自定義模板、多種格式文檔輸出,具備簡潔、輕量、設(shè)計良好、靈活擴展的特點。目前支持MySQL、Oracle、SqlServer、MariaDB、PostgreSQL等數(shù)據(jù)庫,生成文檔目前支持html、word、markdown文檔格式。

二、效果圖展示

三、使用方式

引入依賴jar:

<!--screw數(shù)據(jù)庫表結(jié)構(gòu)文檔生成工具-->
 <dependency>
      <groupId>cn.smallbun.screw</groupId>
      <artifactId>screw-core</artifactId>
      <version>1.0.3</version>
    </dependency>

核心代碼: 

package com.wonders.common.utils;
 
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 lombok.extern.slf4j.Slf4j;
 
import javax.sql.DataSource;
import java.util.ArrayList;
 
/**
 * @Description: TODO:screw數(shù)據(jù)庫表結(jié)構(gòu)文檔生成工具
 * @Author: yyalin
 * 參考網(wǎng)站:https://blog.csdn.net/weixin_49613823/article/details/128600130
 * @CreateDate: 2022/4/27 14:51
 * @Version: V1.0
 */
@Slf4j
public class ScrewUtils {
    public static void runScrew() {
        //MYSQL數(shù)據(jù)源
        HikariConfig hikariConfig = new HikariConfig();
        hikariConfig.setDriverClassName("com.mysql.cj.jdbc.Driver");
//        //hikariConfig.setJdbcUrl("jdbc:mysql://127.0.0.1:3308/test?zeroDateTimeBehavior=convertToNull&useUnicode=true&characterEncoding=UTF-8&serverTimezone=UTC&autoReconnect=true");
//        //TIDB連接
        //hikariConfig.setJdbcUrl("jdbc:mysql://10.1.50.190:4000/CDR?useUnicode=true&characterEncoding=utf8&useSSL=false&zeroDateTimeBehavior=convertToNull");
        hikariConfig.setJdbcUrl("jdbc:mysql://10.1.51.215:3306/KTHDC_MDM?useUnicode=true&characterEncoding=utf8&useSSL=false&zeroDateTimeBehavior=convertToNull");
        hikariConfig.setUsername("root");
        hikariConfig.setPassword("123456");
        //ORACLE數(shù)據(jù)源
//        HikariConfig hikariConfig = new HikariConfig();
//        hikariConfig.setDriverClassName("oracle.jdbc.driver.OracleDriver");
//        hikariConfig.setJdbcUrl("jdbc:oracle:thin:@10.1.51.175:1521/jcpt");
//        hikariConfig.setUsername("CDR");
//        hikariConfig.setPassword("CDR");
 
 
        //設(shè)置可以獲取tables remarks信息 表中文注釋
        hikariConfig.addDataSourceProperty("useInformationSchema", "true");
        hikariConfig.setMinimumIdle(2);
        hikariConfig.setMaximumPoolSize(5);
        DataSource dataSource = new HikariDataSource(hikariConfig);
 
        //生成配置
        EngineConfig engineConfig = EngineConfig.builder()
                //生成文件路徑
                .fileOutputDir("D:\\\\docFile")
                //打開目錄
                .openOutputDir(true)
                //文件類型
                .fileType(EngineFileType.WORD)   //word或html MD
                //生成模板實現(xiàn)
                .produceType(EngineTemplateType.freemarker)
                //自定義文件名稱
                .build();
 
        //配置
        Configuration config = Configuration.builder()
                //版本
                .version("V1.0")
                //描述
                .description("數(shù)據(jù)庫設(shè)計文檔")
                //數(shù)據(jù)源
                .dataSource(dataSource)
                //生成配置
                .engineConfig(engineConfig)
                //生成配置
                .produceConfig(getProcessConfig())
                .build();
        //執(zhí)行生成
        new DocumentationExecute(config).execute();
    }
    /**
     * 功能描述:配置生成對應表的篩選條件
     * @MethodName: getProcessConfig
     * @MethodParam: []
     * @Return: cn.smallbun.screw.core.process.ProcessConfig
     * @Author: yyalin
     * @CreateDate: 2022/4/27 15:15
     */
    public static ProcessConfig getProcessConfig() {
        //忽略表
        ArrayList<String> ignoreTableName = new ArrayList<>();
//        ignoreTableName.add("message");
        //忽略表前綴
        ArrayList<String> ignorePrefix = new ArrayList<>();
//        ignorePrefix.add("act_");
//        ignorePrefix.add("flw_");
        //忽略表后綴
        ArrayList<String> ignoreSuffix = new ArrayList<>();
//        ignoreSuffix.add("_dictionary");
 
        ArrayList<String> designatedTableList = new ArrayList<>();
//        designatedTableList.add("PDCA_DISINFECTION_SUPPLY");
//        designatedTableList.add("PDCA_SURGICAL_INSTRUMENTS");
//        designatedTableList.add("PUB_DIAG_CATA_MAP");
        ProcessConfig processConfig = ProcessConfig.builder()
                //指定生成邏輯、當存在指定表、指定表前綴、指定表后綴時,將生成指定表,其余表不生成、并跳過忽略表配置
                //根據(jù)名稱指定表生成
//                .designatedTableName(new ArrayList<>())
                .designatedTableName(designatedTableList)
                //根據(jù)表前綴生成
                .designatedTablePrefix(new ArrayList<>())
                //根據(jù)表后綴生成
                .designatedTableSuffix(new ArrayList<>())
                //忽略表名
                .ignoreTableName(ignoreTableName)
                //忽略表前綴
                .ignoreTablePrefix(ignorePrefix)
                //忽略表后綴
                .ignoreTableSuffix(ignoreSuffix).build();
        return processConfig;
    }
 
    //臨時使用
    public static void main(String[] args) {
        runScrew();
    }
 
 
 
}

注意:可以通過設(shè)置忽略表名稱、忽略表前綴、忽略表后綴等方式過濾不需要帶出的相關(guān)表,從而達到指定導出的效果。

同樣,可以與springboot更好地集成,只需將上述的參數(shù)配置在yml中即可,通過@Value("${spring.datasource.driver-class-name}")的方式獲取即可。

四、方法補充

除了上文的內(nèi)容,下面小編為大家整理了screw工具的其他應用,希望對大家有所幫助

1.引入庫

pom文件中引入jar依賴

<!--  數(shù)據(jù)庫設(shè)計文檔生成工具-->
<dependency>
    <groupId>cn.smallbun.screw</groupId>
    <artifactId>screw-core</artifactId>
    <version>1.0.5</version>
</dependency>

2.通過命令行工具使用

下載cn.smallbun.screw的JAR文件,并將其添加到項目中。

在命令行中執(zhí)行以下命令:

java -jar screw.jar -url jdbc:mysql://localhost:3306/database -driver com.mysql.jdbc.Driver -username root -password 123456 -type html -outDri doc

上述命令使用MySQL數(shù)據(jù)庫作為示例,根據(jù)實際情況修改數(shù)據(jù)庫連接相關(guān)參數(shù)。通過-type指定輸出文檔的格式,通過-outDri指定輸出路徑。

3.通過Java代碼使用

代碼如下(下面用的是postgres數(shù)據(jù)庫):

 
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.ArrayList;
import java.util.List;
 
public class DatabaseDesignDocUtil {
 
    public static void main(String[] args) {
        documentGeneration();
    }
 
    /**
     * 文檔生成
     */
    public static void documentGeneration() {
        //數(shù)據(jù)源
        HikariConfig hikariConfig = new HikariConfig();
        hikariConfig.setDriverClassName("org.postgresql.Driver");
        hikariConfig.setJdbcUrl("jdbc:postgresql://39.164.52.80:5432/work_face");
        hikariConfig.setUsername("postgres");
        hikariConfig.setPassword("POSTGRES");
        //設(shè)置可以獲取tables remarks信息
        hikariConfig.addDataSourceProperty("useInformationSchema", "true");
        hikariConfig.setMinimumIdle(2);
        hikariConfig.setMaximumPoolSize(5);
        DataSource dataSource = new HikariDataSource(hikariConfig);
        //生成配置
        EngineConfig engineConfig = EngineConfig.builder()
                //生成文件路徑
                .fileOutputDir("C:\\Users\\tarzan\\Desktop\\doc")
                //打開目錄
                .openOutputDir(true)
                //文件類型
                .fileType(EngineFileType.WORD)
                //生成模板實現(xiàn)
                .produceType(EngineTemplateType.freemarker)
                //自定義文件名稱
                .fileName("智能工作面數(shù)據(jù)庫設(shè)計文檔").build();
 
        //忽略表
        List<String> ignoreTableName = new ArrayList<>();
        ignoreTableName.add("test_user");
        ignoreTableName.add("test_group");
        //忽略表前綴
        ArrayList<String> ignorePrefix = new ArrayList<>();
        ignorePrefix.add("test_");
        //忽略表后綴
        ArrayList<String> ignoreSuffix = new ArrayList<>();
        ignoreSuffix.add("_test");
        ProcessConfig processConfig = ProcessConfig.builder()
                //指定生成邏輯、當存在指定表、指定表前綴、指定表后綴時,將生成指定表,其余表不生成、并跳過忽略表配置
                //根據(jù)名稱指定表生成
                .designatedTableName(new ArrayList<>())
                //根據(jù)表前綴生成
                .designatedTablePrefix(new ArrayList<>())
                //根據(jù)表后綴生成
                .designatedTableSuffix(new ArrayList<>())
                //忽略表名
                .ignoreTableName(ignoreTableName)
                //忽略表前綴
                .ignoreTablePrefix(ignorePrefix)
                //忽略表后綴
                .ignoreTableSuffix(ignoreSuffix).build();
        //配置
        Configuration config = Configuration.builder()
                //版本
                .version("1.0.0")
                //描述
                .description("數(shù)據(jù)庫設(shè)計文檔生成")
                //數(shù)據(jù)源
                .dataSource(dataSource)
                //生成配置
                .engineConfig(engineConfig)
                //生成配置
                .produceConfig(processConfig)
                .build();
        //執(zhí)行生成
        new DocumentationExecute(config).execute();
    }
 
}

在上述示例中,我們創(chuàng)建了一個Configuration對象,配置了數(shù)據(jù)庫連接信息和文檔輸出選項。然后,通過DocumentationExecute執(zhí)行文檔生成操作。需要改成mysql等別的數(shù)據(jù)庫的,請在代碼中改下驅(qū)動配置和連接配置。

到此這篇關(guān)于SpringBoot集成screw實現(xiàn)數(shù)據(jù)庫表結(jié)構(gòu)文檔生成的文章就介紹到這了,更多相關(guān)SpringBoot screw數(shù)據(jù)庫文檔生成內(nèi)容請搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!

相關(guān)文章

  • Sentinel的熔斷降級、資源規(guī)則詳解與實例

    Sentinel的熔斷降級、資源規(guī)則詳解與實例

    這篇文章主要介紹了Sentinel的熔斷降級、資源規(guī)則詳解與實例,Sentinel是阿里巴巴開源的一款流量控制和熔斷降級的框架,它主要用于保護分布式系統(tǒng)中的服務(wù)穩(wěn)定性,Sentinel通過對服務(wù)進行流量控制和熔斷降級,可以有效地保護系統(tǒng)的穩(wěn)定性,需要的朋友可以參考下
    2023-09-09
  • springboot如何接收text/plain參數(shù)

    springboot如何接收text/plain參數(shù)

    這篇文章主要介紹了springboot如何接收text/plain參數(shù)的實現(xiàn)方式,具有很好的參考價值,希望對大家有所幫助,如有錯誤或未考慮完全的地方,望不吝賜教
    2025-06-06
  • Java?9中List.of()的使用示例及注意事項

    Java?9中List.of()的使用示例及注意事項

    Java 9引入了一個新的靜態(tài)工廠方法List.of(),用于創(chuàng)建不可變的列表對象,這篇文章主要介紹了Java?9中List.of()的使用示例及注意事項的相關(guān)資料,文中通過代碼介紹的非常詳細,需要的朋友可以參考下
    2025-03-03
  • javaSE中異常如何處理舉例詳解

    javaSE中異常如何處理舉例詳解

    程序運行過程中發(fā)生了不正常的情況,這種不正常的情況叫做異常,下面這篇文章主要給大家介紹了關(guān)于javaSE中異常如何處理的相關(guān)資料,文中通過實例代碼介紹的非常詳細,需要的朋友可以參考下
    2023-01-01
  • 詳解Java中的悲觀鎖與樂觀鎖

    詳解Java中的悲觀鎖與樂觀鎖

    樂觀鎖對應于生活中樂觀的人總是想著事情往好的方向發(fā)展,悲觀鎖對應于生活中悲觀的人總是想著事情往壞的方向發(fā)展.這兩種人各有優(yōu)缺點,不能不以場景而定說一種人好于另外一種人,文中詳細介紹了悲觀鎖與樂觀鎖,需要的朋友可以參考下
    2021-05-05
  • SpringMVC的注解@RequestMapping屬性及使用

    SpringMVC的注解@RequestMapping屬性及使用

    這篇文章主要為大家介紹了SpringMVC注解@RequestMapping屬性及使用,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進步,早日升職加薪
    2022-05-05
  • MybatisPlus中的多表條件排序查詢

    MybatisPlus中的多表條件排序查詢

    這篇文章主要介紹了MybatisPlus中的多表條件排序查詢,具有很好的參考價值,希望對大家有所幫助。如有錯誤或未考慮完全的地方,望不吝賜教
    2022-09-09
  • 詳解PipedInputStream和PipedOutputStream_動力節(jié)點Java學院整理

    詳解PipedInputStream和PipedOutputStream_動力節(jié)點Java學院整理

    這篇文章主要為大家詳細介紹了管道PipedInputStream和PipedOutputStream,具有一定的參考價值,感興趣的小伙伴們可以參考一下
    2017-05-05
  • 通過實例解析Spring Ioc項目實現(xiàn)過程

    通過實例解析Spring Ioc項目實現(xiàn)過程

    這篇文章主要介紹了Spring Ioc項目實踐過程詳解,文中通過示例代碼介紹的非常詳細,對大家的學習或者工作具有一定的參考學習價值,需要的朋友可以參考下
    2020-06-06
  • System.identityHashCode和hashCode的區(qū)別及說明

    System.identityHashCode和hashCode的區(qū)別及說明

    String調(diào)用hashCode()和System.identityHashCode()返回值不同是因為String重寫了hashCode()方法,而System.identityHashCode()返回對象的內(nèi)存地址哈希值;Test調(diào)用兩個方法返回值相同是因為Test沒有重寫hashCode()方法,因此兩者調(diào)用底層的JVM_IHashCode方法返回相同值
    2024-11-11

最新評論

闻喜县| 关岭| 巨野县| 福清市| 鹤岗市| 晋州市| 茂名市| 正定县| 彩票| 丹巴县| 思茅市| 武山县| 辽宁省| 广丰县| 广东省| 佛冈县| 扶绥县| 华宁县| 沾益县| 綦江县| 中牟县| 镇原县| 华蓥市| 海丰县| 溧水县| 东乌| 仙居县| 宜兰市| 环江| 和龙市| 论坛| 景德镇市| 鸡西市| 新兴县| 广宁县| 堆龙德庆县| 黑龙江省| 蓬溪县| 简阳市| 桃江县| 天祝|