激情久久久_欧美视频区_成人av免费_不卡视频一二三区_欧美精品在欧美一区二区少妇_欧美一区二区三区的

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

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

延伸 · 閱讀

精彩推薦
主站蜘蛛池模板: 国产成人精品免费视频大全最热 | 中文字幕免费看 | xxxx18韩国护士hd老师 | 亚洲草逼视频 | 青青草华人在线 | 性欧美性欧美 | 91成人免费版 | 香蕉秀| 黄色三级网站 | 中文有码一区二区 | 中文字幕精品在线视频 | vidz 98hd| 未成年人在线观看 | 性欧美视频在线观看 | 亚洲免费毛片基地 | 久草在线高清 | 亚洲综合一区在线观看 | 国产高潮好爽受不了了夜色 | 久久生活片 | 成人免费在线观看视频 | 99精品无人区乱码在线观看 | 国产免费久久久久 | www.17c亚洲蜜桃 | av在线免费看网站 | 黄色特级| 色综合网在线观看 | 成人在线观看一区 | 精国品产一区二区三区有限公司 | 久久丝袜脚交足黄网站免费 | 午夜精品成人 | 男女污污视频网站 | 国产精品久久在线观看 | xnxx 日本19| 中文字幕网站在线 | 国产大片中文字幕在线观看 | 黑色丝袜美美女被躁视频 | 色综合久久久久久久久久久 | 成人三级黄色片 | 欧美中文字幕一区二区三区亚洲 | 欧美精品v国产精品v日韩精品 | 色人阁在线视频 |