偷偷摘套内射激情视频,久久精品99国产国产精,中文字幕无线乱码人妻,中文在线中文a,性爽19p

太方便!Spring Boot整合Screw:高效生成數(shù)據(jù)庫文檔

開發(fā) 前端
文檔提供了一個清晰的數(shù)據(jù)庫數(shù)據(jù)模型視圖,讓項目團隊成員(如開發(fā)者、測試人員、運維人員等)都能理解數(shù)據(jù)如何存儲、字段的含義、數(shù)據(jù)之間的關(guān)系等。

環(huán)境:SpringBoot3.2.5 + Screw1.0.5

1. 簡介

任何一個項目對于維護一份數(shù)據(jù)庫表結(jié)構(gòu)文檔是至關(guān)重要的,總結(jié)起來有以下原因:

  • 清晰的數(shù)據(jù)模型:
    文檔提供了一個清晰的數(shù)據(jù)庫數(shù)據(jù)模型視圖,讓項目團隊成員(如開發(fā)者、測試人員、運維人員等)都能理解數(shù)據(jù)如何存儲、字段的含義、數(shù)據(jù)之間的關(guān)系等。

便于溝通和協(xié)作:

  • 文檔是團隊成員之間溝通數(shù)據(jù)庫結(jié)構(gòu)的重要工具。當(dāng)需要討論數(shù)據(jù)模型或進行數(shù)據(jù)庫變更時,文檔可以作為參考和討論的起點。

支持變更管理:

  • 當(dāng)數(shù)據(jù)庫結(jié)構(gòu)需要變更時(如添加新字段、修改字段類型、刪除字段等),文檔可以記錄這些變更,并解釋變更的原因和影響。這有助于團隊成員理解并跟蹤數(shù)據(jù)庫結(jié)構(gòu)的變化。

便于新成員快速上手:

  • 對于新加入項目的成員,一份詳細的數(shù)據(jù)庫表結(jié)構(gòu)文檔可以幫助他們快速了解項目的數(shù)據(jù)模型,減少學(xué)習(xí)成本。

提高可維護性:

  • 一份維護良好的數(shù)據(jù)庫表結(jié)構(gòu)文檔可以提高數(shù)據(jù)庫的可維護性。當(dāng)出現(xiàn)問題或需要修復(fù)時,文檔可以幫助開發(fā)者快速定位問題所在,并找到解決方案。

在編寫數(shù)據(jù)庫表結(jié)構(gòu)時,需要投入相當(dāng)?shù)臅r間,并且存在遺漏或錯誤的風(fēng)險。而Screw是一款強大的工具,通過簡單的配置,它就能夠自動生成多種數(shù)據(jù)格式的數(shù)據(jù)庫表結(jié)構(gòu)文檔,從而節(jié)省時間并確保文檔的準(zhǔn)確性和完整性。

2. Screw簡介

2.1 Screw特點

  • 簡潔、輕量、設(shè)計良好
  • 多數(shù)據(jù)庫支持
  • 多種格式文檔
  • 靈活擴展
  • 支持自定義模板

2.2 支持的數(shù)據(jù)庫

MySQL、MariaDB、TIDB、Oracle、SqlServer、PostgreSQL、Cache DB(2016)

2.3 支持的文檔

html

目錄

圖片圖片

具體表

圖片圖片

word

圖片圖片

markdown

目錄

圖片圖片

具體表

圖片圖片

3. 實戰(zhàn)案例

3.1 引入Screw依賴

<dependency>
  <groupId>cn.smallbun.screw</groupId>
  <artifactId>screw-core</artifactId>
  <version>1.0.5</version>
</dependency>

3.2 定義Screw可配置項

public class ScrewProperties {
  /**數(shù)據(jù)庫腳本版本*/
  private String version ;
  /**標(biāo)題*/
  private String title ;
  /**數(shù)據(jù)庫腳本說明*/
  private String desc ;
  /**機構(gòu)*/
  private String org ;
  /**機構(gòu)網(wǎng)址*/
  private String orgUrl ;
  /**是否啟用*/
  private boolean enabled = false ;
  private boolean autoGen = false ;
  /**全局配置*/
  private ScrewConfig config = new ScrewConfig() ;
  /**忽略表設(shè)置*/
  private TableConfig tables = new TableConfig() ;
  public static class TableConfig {
    /**指定生成的表*/
    private List<String> designatedTables = new ArrayList<>() ;
    /**指定生成表的前綴*/
    private List<String> designatedTablePrefixs = new ArrayList<>() ;
    /**指定生成表的后綴*/
    private List<String> designatedTableSuffixs = new ArrayList<>() ;
    /**忽略表*/
    private List<String> ignoreTables = new ArrayList<>() ;
    /**忽略表前綴*/
    private List<String> ignoreTablePrefixs = new ArrayList<>() ;
    /**忽略表后綴*/
    private List<String> ignoreTableSuffixs = new ArrayList<>() ;
  }
  public static class ScrewConfig {
    /**文檔輸出目錄*/
    private String fileOutputDir ;
    /**生成完成是否打開目錄*/
    private boolean openOutputDir = true ;
    /**文檔類型*/
    private EngineFileType fileType = EngineFileType.HTML;
    /**文檔生成模版類型*/
    private EngineTemplateType produceType = EngineTemplateType.freemarker ;
    /**文檔名稱*/
    private String fileName = "數(shù)據(jù)庫設(shè)計文檔" ;
  }
}

生成文檔組件

@Component
public class DatabaseDocComponent {  
  private final DataSource dataSource ;
  private final ScrewProperties screwProperties ;
  public DatabaseDocComponent(DataSource dataSource, ScrewProperties screwProperties) {
    this.dataSource = dataSource ;
    this.screwProperties = screwProperties ;
  }
  public void genDocument() {
    //生成配置
    EngineConfig engineConfig = EngineConfig.builder()
      // 生成文件路徑
      .fileOutputDir(screwProperties.getConfig().getFileOutputDir())
      // 打開目錄
      .openOutputDir(screwProperties.getConfig().isOpenOutputDir())
      // 文件類型
      .fileType(screwProperties.getConfig().getFileType())
      // 生成模板實現(xiàn)
      .produceType(screwProperties.getConfig().getProduceType())
      // 自定義文件名稱
        .fileName(screwProperties.getConfig().getFileName()).build();
    ProcessConfig processConfig = ProcessConfig.builder()
      //指定生成邏輯、當(dāng)存在指定表、指定表前綴、指定表后綴時,將生成指定表,其余表不生成、并跳過忽略表配置  
      //根據(jù)名稱指定表生成
      .designatedTableName(screwProperties.getTables().getDesignatedTables())
      //根據(jù)表前綴生成
      .designatedTablePrefix(screwProperties.getTables().getDesignatedTablePrefixs())
      //根據(jù)表后綴生成  
      .designatedTableSuffix(screwProperties.getTables().getDesignatedTableSuffixs())
          //忽略表名
          .ignoreTableName(screwProperties.getTables().getIgnoreTables())
          //忽略表前綴
          .ignoreTablePrefix(screwProperties.getTables().getIgnoreTablePrefixs())
          //忽略表后綴
          .ignoreTableSuffix(screwProperties.getTables().getIgnoreTableSuffixs()).build();
    //配置
    Configuration config = Configuration.builder()
      //版本
      .version(screwProperties.getVersion())
      .title(screwProperties.getTitle())
      //描述
      .description(screwProperties.getDesc())
      .organization(screwProperties.getOrg())
      .organizationUrl(screwProperties.getOrgUrl())
      //數(shù)據(jù)源
      .dataSource(dataSource)
      //生成配置
      .engineConfig(engineConfig)
      //生成配置
      .produceConfig(processConfig)
      .build() ;
    //執(zhí)行生成
    new DocumentationExecute(config).execute() ;
  }
}

3.3 測試文檔生成

@SpringBootTest
public class ScrewTest {
  @Resource
  private DatabaseDocComponent doc ;
  @Test
  public void testGenDoc() {
    doc.genDocument() ;
  }
}

在你指定的位置生成了文檔;

圖片圖片

圖片圖片


責(zé)任編輯:武曉燕 來源: Spring全家桶實戰(zhàn)案例源碼
相關(guān)推薦

2024-09-27 15:24:15

Spring數(shù)據(jù)加解密

2020-08-06 11:45:37

數(shù)據(jù)庫文檔Swagger

2023-04-28 15:15:39

數(shù)據(jù)庫JPA

2024-11-11 10:02:37

Spring搜索數(shù)據(jù)

2020-12-24 10:20:43

文檔工具語言

2010-05-07 14:29:45

Unix--Tripw

2021-05-10 09:22:44

.NET數(shù)據(jù)庫項目

2024-07-26 10:50:51

SpringScrew數(shù)據(jù)庫

2021-06-29 17:19:44

Spring Boot集成Flyway

2024-01-10 08:17:50

HikariCP數(shù)據(jù)庫Spring

2024-03-26 08:08:08

SpringBPMN模型

2016-08-23 13:35:22

MVCEFNuGet

2024-09-30 08:10:22

2017-12-27 15:16:35

Spring BootFlyway數(shù)據(jù)庫

2023-03-29 07:02:46

開源項目工具

2025-05-09 07:20:02

Spring數(shù)據(jù)庫檢索

2022-12-23 08:28:42

策略模式算法

2025-06-04 02:15:00

數(shù)據(jù)庫連接方式JDBC

2025-07-02 07:33:02

Spring倒排索引分布式

2012-07-23 14:30:33

Oracle
點贊
收藏

51CTO技術(shù)棧公眾號