一区二区三区在线-一区二区三区亚洲视频-一区二区三区亚洲-一区二区三区午夜-一区二区三区四区在线视频-一区二区三区四区在线免费观看

服務器之家:專注于服務器技術及軟件下載分享
分類導航

PHP教程|ASP.NET教程|Java教程|ASP教程|編程技術|正則表達式|C/C++|IOS|C#|Swift|Android|VB|R語言|JavaScript|易語言|vb.net|

服務器之家 - 編程語言 - Java教程 - SpringBoot整合screw實現數據庫文檔自動生成的示例代碼

SpringBoot整合screw實現數據庫文檔自動生成的示例代碼

2020-09-23 10:41周兆東 Java教程

這篇文章主要介紹了SpringBoot整合screw實現數據庫文檔自動生成的示例代碼,文中通過示例代碼介紹的非常詳細,對大家的學習或者工作具有一定的參考學習價值,需要的朋友們下面隨著小編來一起學習學習吧

有時候數據庫文檔需要整理,可是只能手動的復制粘貼,心中一萬只草泥馬奔騰而過。。。

screw

簡潔好用的數據庫表結構文檔生成工具。

1. 創建項目

1.1 pom.xml

?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
<dependency>
  <groupId>mysql</groupId>
  <artifactId>mysql-connector-java</artifactId>
  <scope>runtime</scope>
</dependency>
 
<dependency>
  <groupId>org.freemarker</groupId>
  <artifactId>freemarker</artifactId>
  <version>2.3.30</version>
</dependency>
 
<dependency>
  <groupId>cn.smallbun.screw</groupId>
  <artifactId>screw-core</artifactId>
  <version>1.0.5</version>
</dependency>

1.2 新建工具類DocumentConfig.java

?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
/**
   * 文檔生成
   */
  static void documentGeneration() {
    //數據源
    HikariConfig hikariConfig = new HikariConfig();
    hikariConfig.setDriverClassName("com.mysql.cj.jdbc.Driver");
    hikariConfig.setJdbcUrl("jdbc:mysql://IP地址:3306/數據庫名稱");
    hikariConfig.setUsername("用戶名");
    hikariConfig.setPassword("密碼");
    //設置可以獲取tables remarks信息
    hikariConfig.addDataSourceProperty("useInformationSchema", "true");
    hikariConfig.setMinimumIdle(2);
    hikariConfig.setMaximumPoolSize(5);
    DataSource dataSource = new HikariDataSource(hikariConfig);
    //生成配置
    EngineConfig engineConfig = EngineConfig.builder()
        //生成文件路徑
        .fileOutputDir("D:\\")
        //打開目錄
        .openOutputDir(true)
        //文件類型
        .fileType(EngineFileType.HTML)
        //生成模板實現
        .produceType(EngineTemplateType.freemarker)
        //自定義文件名稱
        .fileName("test數據庫").build();
 
    //忽略表
    ArrayList<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()
        //指定生成邏輯、當存在指定表、指定表前綴、指定表后綴時,將生成指定表,其余表不生成、并跳過忽略表配置
        //根據名稱指定表生成
        .designatedTableName(new ArrayList<>())
        //根據表前綴生成
        .designatedTablePrefix(new ArrayList<>())
        //根據表后綴生成
        .designatedTableSuffix(new ArrayList<>())
        //忽略表名
        .ignoreTableName(ignoreTableName)
        //忽略表前綴
        .ignoreTablePrefix(ignorePrefix)
        //忽略表后綴
        .ignoreTableSuffix(ignoreSuffix).build();
    //配置
    Configuration config = Configuration.builder()
        //版本
        .version("1.0.0")
        //描述
        .description("數據庫設計文檔生成")
        //數據源
        .dataSource(dataSource)
        //生成配置
        .engineConfig(engineConfig)
        //生成配置
        .produceConfig(processConfig)
        .build();
    //執行生成
    new DocumentationExecute(config).execute();
  }

1.3 運行該方法

SpringBoot整合screw實現數據庫文檔自動生成的示例代碼

1.4 第二種生成配置

1.4.1 先在application.yml里面配置數據庫連接信息:

?
1
2
3
4
5
6
7
8
9
spring:
 datasource:
  driver-class-name: com.mysql.cj.jdbc.Driver
  url: jdbc:mysql://IP地址:3306/數據庫名稱
  username: 用戶名
  password: 密碼
  xa:
   properties:
    useInformationSchema: true

1.4.2 新建test方法

?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
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 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
public class ScrewApplicationTests {
 
  @Autowired
  ApplicationContext applicationContext;
 
  @Test
  void contextLoads() {
    DataSource dataSourceMysql = applicationContext.getBean(DataSource.class);
 
    // 生成文件配置
    EngineConfig engineConfig = EngineConfig.builder()
        // 生成文件路徑,自己mac本地的地址,這里需要自己更換下路徑
        .fileOutputDir("D:\\")
        // 打開目錄
        .openOutputDir(false)
        // 文件類型
        .fileType(EngineFileType.HTML)
        // 生成模板實現
        .produceType(EngineTemplateType.freemarker).build();
 
    // 生成文檔配置(包含以下自定義版本號、描述等配置連接)
    Configuration config = Configuration.builder()
        .version("1.0.0")
        .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();
  }
 
}

1.4.3 運行test方法生成

SpringBoot整合screw實現數據庫文檔自動生成的示例代碼

GitHub代碼地址:

github.com/zhouzhaodong/springboot/tree/master/spring-boot-screw

到此這篇關于SpringBoot整合screw實現數據庫文檔自動生成的示例代碼的文章就介紹到這了,更多相關SpringBoot數據庫文檔自動生成內容請搜索服務器之家以前的文章或繼續瀏覽下面的相關文章希望大家以后多多支持服務器之家!

原文鏈接:https://segmentfault.com/a/1190000024542624

延伸 · 閱讀

精彩推薦
主站蜘蛛池模板: 网友自拍咪咪爱 | 亚洲 日本 天堂 国产 在线 | 国产一级特黄在线播放 | yy3341殇情影院理论片 | 小辣椒精品福利视频导航 | 嗯啊在线观看免费影院 | 私人影院在线播放 | 亚洲第成色999久久网站 | 日韩亚洲人成在线 | 日本三级做a全过程在线观看 | 国产高清国内精品福利色噜噜 | 乌克兰17一18处交 | 奇米影视7777久久精品 | 日本www色| 亚洲2023无矿砖码砖区 | 污文啊好棒棒啊好了 | 香蕉eeww99国产精品 | 亚洲美女人黄网成人女 | 亚洲精品成人456在线播放 | 暖暖在线日本 | 日本艳鉧动漫1~6完整版在 | 美女光屁股网站 | 国色天香视频完整版 | 爱操综合网| 国产综合成色在线视频 | 日本妻子迷妹网 | 欧美日韩国产最新一区二区 | 亚洲免费闲人蜜桃 | chanelpreston欧美网站 | 成人激情 | 日韩大片免费观看 | 国产成人高清精品免费观看 | 欧美第一视频 | 狠狠的撞进去嗯啊h女强男视频 | 好爽视频| 日韩欧美国产综合精品 | 人人人人看人人人做人人 | 日老逼| 糖心vlog网页版 | tube8老师| 成年视频在线观看免费 |