SpringBoot中集成screw(螺絲釘)實(shí)現(xiàn)數(shù)據(jù)庫(kù)表結(jié)構(gòu)文檔生成方法
場(chǎng)景
經(jīng)常會(huì)有編寫(xiě)數(shù)據(jù)庫(kù)表結(jié)構(gòu)文檔的時(shí)間付出,那能否通過(guò)簡(jiǎn)單配置實(shí)現(xiàn)自動(dòng)生成。
screw
screw (螺絲釘) 英:[skru?] ~ 簡(jiǎn)潔好用的數(shù)據(jù)庫(kù)表結(jié)構(gòu)文檔生成工具。
https://gitee.com/leshalv/screw
特點(diǎn)
簡(jiǎn)潔、輕量、設(shè)計(jì)良好
多數(shù)據(jù)庫(kù)支持
多種格式文檔
靈活擴(kuò)展
支持自定義模板
數(shù)據(jù)庫(kù)支持
MySQL
MariaDB
TIDB
Oracle
SqlServer
PostgreSQL
Cache DB(2016)
H2 (開(kāi)發(fā)中)
DB2 (開(kāi)發(fā)中)
HSQL (開(kāi)發(fā)中)
SQLite(開(kāi)發(fā)中)
瀚高(開(kāi)發(fā)中)
達(dá)夢(mèng) (開(kāi)發(fā)中)
虛谷 (開(kāi)發(fā)中)
人大金倉(cāng)(開(kāi)發(fā)中)
文檔生成支持
html
word
markdown
實(shí)現(xiàn)
下面以連接mysql數(shù)據(jù)庫(kù)并生成html格式的數(shù)據(jù)庫(kù)結(jié)構(gòu)文檔為例
插件的使用方式除可以使用代碼外,還可以使用Maven插件的方式。
這里考慮將其集成到單獨(dú)的springboot項(xiàng)目中,并使用單元測(cè)試的方式需要時(shí)配置和運(yùn)行。
新建springboot項(xiàng)目,并引入screw的依賴(lài)
<dependency>
<groupId>cn.smallbun.screw</groupId>
<artifactId>screw-core</artifactId>
<version>1.0.3</version>
</dependency>maven倉(cāng)庫(kù)地址
https://mvnrepository.com/artifact/cn.smallbun.screw/screw-core
然后生成文檔還需依賴(lài)
<dependency>
<groupId>org.freemarker</groupId>
<artifactId>freemarker</artifactId>
<version>2.3.30</version>
</dependency>這里還需要連接mysql數(shù)據(jù)庫(kù)以及單元測(cè)試等的依賴(lài)
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-jdbc</artifactId>
</dependency>
<!--MySQL驅(qū)動(dòng)-->
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
</dependency> 新建單元測(cè)試類(lèi)
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
class ScrewTest {
@Autowired
ApplicationContext applicationContext;
@Test
void createDataBaseWorld() {
DataSource dataSourceMysql = applicationContext.getBean(DataSource.class);
// 生成文件配置
EngineConfig engineConfig = EngineConfig.builder()
// 生成文件路徑,自己mac本地的地址,這里需要自己更換下路徑
.fileOutputDir("D:\\test\\badao\\")
// 打開(kāi)目錄
.openOutputDir(false)
// 文件類(lèi)型
.fileType(EngineFileType.HTML)
// 生成模板實(shí)現(xiàn)
.produceType(EngineTemplateType.freemarker).build();
// 生成文檔配置(包含以下自定義版本號(hào)、描述等配置連接)
Configuration config = Configuration.builder()
.version("1.0.3")
.description("badao")
.dataSource(dataSourceMysql)
.engineConfig(engineConfig)
.produceConfig(getProcessConfig())
.build();
// 執(zhí)行生成
new DocumentationExecute(config).execute();
}
/**
* 配置想要生成的表+ 配置想要忽略的表
* @return 生成表配置
*/
public static ProcessConfig getProcessConfig(){
// 忽略表名
List<String> ignoreTableName = Arrays.asList("test_users","test1");
// 忽略表前綴,如忽略a開(kāi)頭的數(shù)據(jù)庫(kù)表
List<String> ignorePrefix = Arrays.asList("qrtz","sys","gen");
// 忽略表后綴
List<String> ignoreSuffix = Arrays.asList("_log");
return ProcessConfig.builder()
//根據(jù)名稱(chēng)指定表生成
.designatedTableName(new ArrayList<>())
//根據(jù)表前綴生成
.designatedTablePrefix(new ArrayList<>())
//根據(jù)表后綴生成
.designatedTableSuffix(new ArrayList<>())
//忽略表名
.ignoreTableName(ignoreTableName)
//忽略表前綴
.ignoreTablePrefix(ignorePrefix)
//忽略表后綴
.ignoreTableSuffix(ignoreSuffix).build();
}
}這里要注意引入依賴(lài)的路徑。
然后這里需要在配置文件這里是yml中配置數(shù)據(jù)源
# 數(shù)據(jù)源
spring:
application:
name: badao-tcp-demo
datasource:
url: jdbc:mysql://localhost:3306/test?useUnicode=true&characterEncoding=utf8&zeroDateTimeBehavior=convertToNull&useSSL=true&serverTimezone=GMT%2B8
username: root
password: root
driver-class-name: com.mysql.cj.jdbc.Driver
dbcp2:
min-idle: 5 # 數(shù)據(jù)庫(kù)連接池的最小維持連接數(shù)
initial-size: 5 # 初始化連接數(shù)
max-total: 5 # 最大連接數(shù)
max-wait-millis: 150 # 等待連接獲取的最大超時(shí)時(shí)間然后再上面單元測(cè)試中還可配置要忽略的表,指定前后綴等。
運(yùn)行該單元測(cè)試,到配置的指定目錄下查看

到此這篇關(guān)于SpringBoot中集成screw(螺絲釘)實(shí)現(xiàn)數(shù)據(jù)庫(kù)表結(jié)構(gòu)文檔生成的文章就介紹到這了,更多相關(guān)SpringBoot中集成screw(螺絲釘)實(shí)現(xiàn)數(shù)據(jù)庫(kù)表結(jié)構(gòu)文檔生成內(nèi)容請(qǐng)搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!
相關(guān)文章
SpringBoot使用Redis實(shí)現(xiàn)消息隊(duì)列的方法小結(jié)
在應(yīng)用中把Redis當(dāng)成消息隊(duì)列來(lái)使用已經(jīng)屢見(jiàn)不鮮了,我想主要原因是當(dāng)代應(yīng)用十有八九都會(huì)用到 Redis,因此不用再引入其他消息隊(duì)列系統(tǒng),而且Redis提供了好幾種實(shí)現(xiàn)消息隊(duì)列的方法,用起來(lái)也簡(jiǎn)單,本文給大家介紹了SpringBoot使用Redis實(shí)現(xiàn)消息隊(duì)列的方法小結(jié)2024-04-04
Mybatis-Plus處理Mysql?Json類(lèi)型字段的詳細(xì)教程
這篇文章主要給大家介紹了關(guān)于Mybatis-Plus處理Mysql?Json類(lèi)型字段的詳細(xì)教程,Mybatis-Plus可以很方便地處理JSON字段,在實(shí)體類(lèi)中可以使用@JSONField注解來(lái)標(biāo)記JSON字段,同時(shí)在mapper.xml中使用json函數(shù)來(lái)操作JSON字段,需要的朋友可以參考下2024-01-01
SpringBoot進(jìn)行模塊化開(kāi)發(fā)的5種組織方式小結(jié)
模塊化開(kāi)發(fā)作為解決復(fù)雜性的關(guān)鍵策略,能夠有效提升代碼的可維護(hù)性、可擴(kuò)展性和團(tuán)隊(duì)協(xié)作效率,本文將介紹SpringBoot模塊化開(kāi)發(fā)的5種組織方式,需要的小伙伴可以參考一下2025-06-06
Java編寫(xiě)計(jì)算器的常見(jiàn)方法實(shí)例總結(jié)
這篇文章主要介紹了Java編寫(xiě)計(jì)算器的常見(jiàn)方法,結(jié)合實(shí)例形式總結(jié)分析了Java實(shí)現(xiàn)計(jì)算器功能的常用方法,需要的朋友可以參考下2016-04-04
SpringBoot框架集成token實(shí)現(xiàn)登錄校驗(yàn)功能
這篇文章主要為大家詳細(xì)介紹了SpringBoot框架集成token實(shí)現(xiàn)登錄校驗(yàn)功能,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2019-08-08
MybatisPlus,無(wú)XML分分鐘實(shí)現(xiàn)CRUD操作
這篇文章主要介紹了MybatisPlus,無(wú)XML分分鐘實(shí)現(xiàn)CRUD操作,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過(guò)來(lái)看看吧2020-08-08
SpringBoot攔截器實(shí)現(xiàn)API安全驗(yàn)證的示例詳解
在開(kāi)放平臺(tái)和第三方集成的項(xiàng)目中,如何確保 API 調(diào)用的安全性和可靠性是一個(gè)重要課題,本文將詳細(xì)介紹如何基于 Spring Boot 攔截器和 HMAC-SHA256 算法,構(gòu)建一套輕量級(jí)但足夠安全的 API 驗(yàn)簽機(jī)制,希望對(duì)大家有所幫助2025-11-11
SpringBoot項(xiàng)目中報(bào)錯(cuò)The field screenShot exceeds&n
這篇文章主要介紹了SpringBoot項(xiàng)目中報(bào)錯(cuò)The field screenShot exceeds its maximum permitted size of 1048576 bytes.的問(wèn)題及解決,希望對(duì)大家有所幫助,如有錯(cuò)誤或未考慮完全的地方,望不吝賜教2025-04-04

