SpringBoot中集成screw(螺絲釘)實現(xiàn)數(shù)據(jù)庫表結(jié)構(gòu)文檔生成方法
場景
經(jīng)常會有編寫數(shù)據(jù)庫表結(jié)構(gòu)文檔的時間付出,那能否通過簡單配置實現(xiàn)自動生成。
screw
screw (螺絲釘) 英:[skru?] ~ 簡潔好用的數(shù)據(jù)庫表結(jié)構(gòu)文檔生成工具。
https://gitee.com/leshalv/screw
特點
簡潔、輕量、設(shè)計良好
多數(shù)據(jù)庫支持
多種格式文檔
靈活擴展
支持自定義模板
數(shù)據(jù)庫支持
MySQL
MariaDB
TIDB
Oracle
SqlServer
PostgreSQL
Cache DB(2016)
H2 (開發(fā)中)
DB2 (開發(fā)中)
HSQL (開發(fā)中)
SQLite(開發(fā)中)
瀚高(開發(fā)中)
達夢 (開發(fā)中)
虛谷 (開發(fā)中)
人大金倉(開發(fā)中)
文檔生成支持
html
word
markdown
實現(xiàn)
下面以連接mysql數(shù)據(jù)庫并生成html格式的數(shù)據(jù)庫結(jié)構(gòu)文檔為例
插件的使用方式除可以使用代碼外,還可以使用Maven插件的方式。
這里考慮將其集成到單獨的springboot項目中,并使用單元測試的方式需要時配置和運行。
新建springboot項目,并引入screw的依賴
<dependency>
<groupId>cn.smallbun.screw</groupId>
<artifactId>screw-core</artifactId>
<version>1.0.3</version>
</dependency>maven倉庫地址
https://mvnrepository.com/artifact/cn.smallbun.screw/screw-core
然后生成文檔還需依賴
<dependency>
<groupId>org.freemarker</groupId>
<artifactId>freemarker</artifactId>
<version>2.3.30</version>
</dependency>這里還需要連接mysql數(shù)據(jù)庫以及單元測試等的依賴
<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ū)動-->
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
</dependency> 新建單元測試類
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\\")
// 打開目錄
.openOutputDir(false)
// 文件類型
.fileType(EngineFileType.HTML)
// 生成模板實現(xiàn)
.produceType(EngineTemplateType.freemarker).build();
// 生成文檔配置(包含以下自定義版本號、描述等配置連接)
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開頭的數(shù)據(jù)庫表
List<String> ignorePrefix = Arrays.asList("qrtz","sys","gen");
// 忽略表后綴
List<String> ignoreSuffix = Arrays.asList("_log");
return ProcessConfig.builder()
//根據(jù)名稱指定表生成
.designatedTableName(new ArrayList<>())
//根據(jù)表前綴生成
.designatedTablePrefix(new ArrayList<>())
//根據(jù)表后綴生成
.designatedTableSuffix(new ArrayList<>())
//忽略表名
.ignoreTableName(ignoreTableName)
//忽略表前綴
.ignoreTablePrefix(ignorePrefix)
//忽略表后綴
.ignoreTableSuffix(ignoreSuffix).build();
}
}這里要注意引入依賴的路徑。
然后這里需要在配置文件這里是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ù)庫連接池的最小維持連接數(shù)
initial-size: 5 # 初始化連接數(shù)
max-total: 5 # 最大連接數(shù)
max-wait-millis: 150 # 等待連接獲取的最大超時時間然后再上面單元測試中還可配置要忽略的表,指定前后綴等。
運行該單元測試,到配置的指定目錄下查看

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

