SpringBoot集成screw實(shí)現(xiàn)數(shù)據(jù)庫(kù)文檔生成的代碼示例
1.什么是screw?
在企業(yè)級(jí)開發(fā)中、我們經(jīng)常會(huì)有編寫數(shù)據(jù)庫(kù)表結(jié)構(gòu)文檔的時(shí)間付出,從業(yè)以來(lái),待過(guò)幾家企業(yè),關(guān)于數(shù)據(jù)庫(kù)表結(jié)構(gòu)文檔狀態(tài):要么沒有、要么有、但都是手寫、后期運(yùn)維開發(fā),需要手動(dòng)進(jìn)行維護(hù)到文檔中,很是繁瑣、如果忘記一次維護(hù)、就會(huì)給以后工作造成很多困擾、無(wú)形中制造了很多坑留給自己和后人
數(shù)據(jù)庫(kù)支持
- MySQL
- MariaDB
- TIDB
- Oracle
- SqlServer
- PostgreSQL
- Cache DB(2016)
- H2 (開發(fā)中)
- DB2 (開發(fā)中)
- HSQL (開發(fā)中)
- SQLite(開發(fā)中)
2.環(huán)境準(zhǔn)備
參考之前springboot對(duì)接mysql的教程里面的mysql環(huán)境搭建 http://www.liuhaihua.cn/archives/710165.html
3.代碼工程
實(shí)驗(yàn)?zāi)康?/h3>
生成mysql數(shù)據(jù)庫(kù)的word文檔
pom.xml
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<parent>
<artifactId>springboot-demo</artifactId>
<groupId>com.et</groupId>
<version>1.0-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>Screw</artifactId>
<properties>
<maven.compiler.source>8</maven.compiler.source>
<maven.compiler.target>8</maven.compiler.target>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-autoconfigure</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>cn.smallbun.screw</groupId>
<artifactId>screw-core</artifactId>
<version>1.0.5</version>
</dependency>
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jdbc</artifactId>
</dependency>
</dependencies>
</project>
生成類
package com.et.screw;
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.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.ApplicationArguments;
import org.springframework.boot.ApplicationRunner;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.ApplicationContext;
import javax.sql.DataSource;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
@SpringBootApplication
public class Application implements ApplicationRunner {
@Autowired
ApplicationContext applicationContext;
public static void main(String[] args) {
SpringApplication.run(Application.class, args);
}
@Override
public void run(ApplicationArguments args) throws Exception {
DataSource dataSourceMysql = applicationContext.getBean(DataSource.class);
//模板引擎配置 生成文件配置
EngineConfig engineConfig = EngineConfig.builder()
// 生成文件路徑
.fileOutputDir("D://tmp/")
// 打開目錄
.openOutputDir(false)
// 文件類型
.fileType(EngineFileType.WORD)
// 生成模板實(shí)現(xiàn)
.produceType(EngineTemplateType.freemarker).build();
// 生成文檔配置(包含以下自定義版本號(hào)、描述等配置連接),文檔名稱拼接:數(shù)據(jù)庫(kù)名_描述_版本.擴(kuò)展名
Configuration config = Configuration.builder()
.title("數(shù)據(jù)庫(kù)文檔")
// 版本號(hào)
.version("1.0.0")
// 描述
.description("數(shù)據(jù)庫(kù)設(shè)計(jì)文檔")
// 數(shù)據(jù)源
.dataSource(dataSourceMysql)
// 模板引擎配置
.engineConfig(engineConfig)
// 加載配置:想要生成的表、想要忽略的表
.produceConfig(getProcessConfig())
.build();
// 執(zhí)行生成
new DocumentationExecute(config).execute();
}
/**
* 配置想要生成的表+ 配置想要忽略的表
*
* @return 生成表配置
*/
public static ProcessConfig getProcessConfig() {
// 忽略表名
List<String> ignoreTableName = Arrays.asList("");
return ProcessConfig.builder()
//根據(jù)名稱指定表生成
.designatedTableName(new ArrayList<>())
//根據(jù)表前綴生成
.designatedTablePrefix(new ArrayList<>())
//根據(jù)表后綴生成
.designatedTableSuffix(new ArrayList<>())
//忽略表名
.ignoreTableName(ignoreTableName)
.build();
}
}
application.properties
spring.datasource.driverClassName=com.mysql.cj.jdbc.Driver spring.datasource.url=jdbc:mysql://127.0.0.1:3306/jwordpress?useUnicode=true&characterEncoding=utf-8&autoReconnect=true&failOverReadOnly=false&useSSL=false&serverTimezone=Asia/Shanghai spring.datasource.username=root spring.datasource.password=123456
以上只是一些關(guān)鍵代碼,所有代碼請(qǐng)參見下面代碼倉(cāng)庫(kù)
代碼倉(cāng)庫(kù)
4.測(cè)試
啟動(dòng)Spring boot Application,在D://tmp/查看生成的文件

5.引用
https://gitee.com/leshalv/screw
到此這篇關(guān)于SpringBoot集成screw實(shí)現(xiàn)數(shù)據(jù)庫(kù)文檔生成的代碼示例的文章就介紹到這了,更多相關(guān)SpringBoot screw數(shù)據(jù)庫(kù)文檔生成內(nèi)容請(qǐng)搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!
- SpringBoot整合screw實(shí)現(xiàn)自動(dòng)生成數(shù)據(jù)庫(kù)設(shè)計(jì)文檔
- SpringBoot整合screw實(shí)現(xiàn)數(shù)據(jù)庫(kù)文檔自動(dòng)生成的示例代碼
- SpringBoot+?Sharding?Sphere?輕松實(shí)現(xiàn)數(shù)據(jù)庫(kù)字段加解密功能
- SpringBoot項(xiàng)目整合MybatisPlus并使用SQLite作為數(shù)據(jù)庫(kù)的過(guò)程
- SpringBoot項(xiàng)目中枚舉類型字段與前端和數(shù)據(jù)庫(kù)的交互方法
相關(guān)文章
使用MAT進(jìn)行JVM內(nèi)存分析實(shí)例
這篇文章主要介紹了使用MAT進(jìn)行JVM內(nèi)存分析實(shí)例,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。如有錯(cuò)誤或未考慮完全的地方,望不吝賜教2023-04-04
Idea?編譯并運(yùn)行?Spark?3.1.1?源碼的方法
這篇文章主要介紹了Idea?編譯并運(yùn)行?Spark?3.1.1源碼,本文給大家介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或工作具有一定的參考借鑒價(jià)值,需要的朋友可以參考下2022-11-11
Java 8中Collectors.toMap空指針異常源碼解析
這篇文章主要為大家介紹了Java 8中Collectors.toMap空指針異常源碼解析,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進(jìn)步,早日升職加薪2023-08-08
Java加權(quán)負(fù)載均衡策略實(shí)現(xiàn)過(guò)程解析
這篇文章主要介紹了Java加權(quán)負(fù)載均衡策略實(shí)現(xiàn)過(guò)程解析,文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友可以參考下2020-03-03
spring框架cacheAnnotation緩存注釋聲明解析
這篇文章主要介紹了spring框架中cacheAnnotation注釋聲明緩存解析示例有需要的朋友可以借鑒參考下,希望能夠有所幫助2021-10-10
Java swing實(shí)現(xiàn)酒店管理系統(tǒng)
這篇文章主要為大家詳細(xì)介紹了Java swing實(shí)現(xiàn)酒店管理系統(tǒng),文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2019-02-02

