SpringBoot集成screw實(shí)現(xiàn)數(shù)據(jù)庫文檔生成的代碼示例
1.什么是screw?
在企業(yè)級(jí)開發(fā)中、我們經(jīng)常會(huì)有編寫數(shù)據(jù)庫表結(jié)構(gòu)文檔的時(shí)間付出,從業(yè)以來,待過幾家企業(yè),關(guān)于數(shù)據(jù)庫表結(jié)構(gòu)文檔狀態(tài):要么沒有、要么有、但都是手寫、后期運(yùn)維開發(fā),需要手動(dòng)進(jìn)行維護(hù)到文檔中,很是繁瑣、如果忘記一次維護(hù)、就會(huì)給以后工作造成很多困擾、無形中制造了很多坑留給自己和后人
數(shù)據(jù)庫支持
- 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ù)庫的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ù)庫名_描述_版本.擴(kuò)展名 Configuration config = Configuration.builder() .title("數(shù)據(jù)庫文檔") // 版本號(hào) .version("1.0.0") // 描述 .description("數(shù)據(jù)庫設(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)參見下面代碼倉庫
代碼倉庫
4.測試
啟動(dòng)Spring boot Application,在D://tmp/
查看生成的文件
5.引用
https://gitee.com/leshalv/screw
到此這篇關(guān)于SpringBoot集成screw實(shí)現(xiàn)數(shù)據(jù)庫文檔生成的代碼示例的文章就介紹到這了,更多相關(guān)SpringBoot screw數(shù)據(jù)庫文檔生成內(nèi)容請(qǐng)搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!
相關(guān)文章
記錄jdk21連接SQLServer因?yàn)門LS協(xié)議報(bào)錯(cuò)問題
在使用Druid連接池連接SQL Server時(shí),可能會(huì)遇到因TLS版本不匹配導(dǎo)致的連接失敗問題,具體表現(xiàn)為客戶端使用TLS1.3或TLS1.2,而SQL Server僅支持TLS1.0,導(dǎo)致無法建立安全連接,解決方法是修改JDK的安全配置,啟用TLS1.02024-10-10Java中的MessageFormat.format用法實(shí)例
這篇文章主要介紹了Java中的MessageFormat.format用法實(shí)例,本文先是講解了MessageFormat的語法,然后給出了多個(gè)操作實(shí)例,需要的朋友可以參考下2015-06-06Spring BeanFactory和FactoryBean區(qū)別解析
這篇文章主要介紹了Spring BeanFactory和FactoryBean區(qū)別解析,文中通過示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友可以參考下2020-03-03關(guān)于java中基本數(shù)據(jù)類型的數(shù)值范圍
這篇文章主要介紹了關(guān)于java中基本數(shù)據(jù)類型的數(shù)值范圍,基本類型,或者叫做內(nèi)置類型,是JAVA中不同于類的特殊類型,它們是我們編程中使用最頻繁的類型,需要的朋友可以參考下2023-07-07Springboot整合itext實(shí)現(xiàn)PDF文件合并
這篇文章主要為大家詳細(xì)介紹了Springboot整合itext實(shí)現(xiàn)PDF文件合并以及識(shí)別圖片轉(zhuǎn)成PDF拼接的相關(guān)知識(shí),感興趣的小伙伴可以跟隨小編一起學(xué)習(xí)一下2024-11-11Spring-data-redis操作redis知識(shí)總結(jié)
這篇文章主要介紹了Spring-data-redis操作redis知識(shí)總結(jié),spring-data-redis是spring-data模塊的一部分,專門用來支持在spring管理項(xiàng)目對(duì)redis的操作。2017-04-04解決springboot jpa @Column columnDefinition等屬性失效問題
這篇文章主要介紹了解決springboot jpa @Column columnDefinition等屬性失效問題,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。如有錯(cuò)誤或未考慮完全的地方,望不吝賜教2021-10-10java 查找list中重復(fù)數(shù)據(jù)實(shí)例詳解
這篇文章主要介紹了java 查找list中重復(fù)數(shù)據(jù)實(shí)例詳解的相關(guān)資料,需要的朋友可以參考下2017-01-01