您好,登錄后才能下訂單哦!
本篇內(nèi)容介紹了“怎么一鍵生成數(shù)據(jù)庫文檔”的有關(guān)知識(shí),在實(shí)際案例的操作過程中,不少人都會(huì)遇到這樣的困境,接下來就讓小編帶領(lǐng)大家學(xué)習(xí)一下如何處理這些情況吧!希望大家仔細(xì)閱讀,能夠?qū)W有所成!
數(shù)據(jù)庫文檔圖
引入screw
核心包,HikariCP
數(shù)據(jù)庫連接池,HikariCP
號(hào)稱性能最出色的數(shù)據(jù)庫連接池。
<!-- screw核心 -->
<dependency>
<groupId>cn.smallbun.screw</groupId>
<artifactId>screw-core</artifactId>
<version>1.0.3</version>
</dependency>
<!-- HikariCP -->
<dependency>
<groupId>com.zaxxer</groupId>
<artifactId>HikariCP</artifactId>
<version>3.4.5</version>
</dependency>
<!--mysql driver-->
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>8.0.20</version>
</dependency>
配置數(shù)據(jù)源,設(shè)置
useInformationSchema
可以獲取tables
注釋信息。
spring.datasource.url=jdbc:mysql://45.93.1.5:3306/fire?useUnicode=true&characterEncoding=UTF-8&useSSL=false
spring.datasource.username=root
spring.datasource.password=123456
spring.datasource.driver-class-name=com.mysql.cj.jdbc.Driver
spring.datasource.xa.properties.useInformationSchema=true
screw
有兩種執(zhí)行方式,第一種是pom
文件配置,另一種是代碼執(zhí)行。
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
<plugin>
<groupId>cn.smallbun.screw</groupId>
<artifactId>screw-maven-plugin</artifactId>
<version>1.0.3</version>
<dependencies>
<!-- HikariCP -->
<dependency>
<groupId>com.zaxxer</groupId>
<artifactId>HikariCP</artifactId>
<version>3.4.5</version>
</dependency>
<!--mysql driver-->
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>8.0.20</version>
</dependency>
</dependencies>
<configuration>
<!--username-->
<username>root</username>
<!--password-->
<password>123456</password>
<!--driver-->
<driverClassName>com.mysql.cj.jdbc.Driver</driverClassName>
<!--jdbc url-->
<jdbcUrl>jdbc:mysql://41.92.6.5:3306/fire</jdbcUrl>
<!--生成文件類型-->
<fileType>HTML</fileType>
<!--打開文件輸出目錄-->
<openOutputDir>false</openOutputDir>
<!--生成模板-->
<produceType>freemarker</produceType>
<!--文檔名稱 為空時(shí):將采用[數(shù)據(jù)庫名稱-描述-版本號(hào)]作為文檔名稱-->
<!--<docName>測(cè)試文檔名稱</docName>-->
<!--描述-->
<description>數(shù)據(jù)庫文檔生成</description>
<!--版本-->
<version>${project.version}</version>
<!--標(biāo)題-->
<title>fire數(shù)據(jù)庫文檔</title>
</configuration>
<executions>
<execution>
<phase>compile</phase>
<goals>
<goal>run</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
配置完以后在
maven project
->screw
雙擊執(zhí)行ok。
代碼生成方式也非常簡單。
@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)
// 生成模板實(shí)現(xiàn)
.produceType(EngineTemplateType.freemarker).build();
// 生成文檔配置(包含以下自定義版本號(hào)、描述等配置連接)
Configuration config = Configuration.builder()
.version("1.0.3")
.description("生成文檔信息描述")
.dataSource(dataSourceMysql)
.engineConfig(engineConfig)
.produceConfig(getProcessConfig())
.build();
// 執(zhí)行生成
new DocumentationExecute(config).execute();
}
/**
* 配置想要生成的表+ 配置想要忽略的表
*
* @return 生成表配置
*/
public static ProcessConfig getProcessConfig() {
// 忽略表名
List<String> ignoreTableName = Arrays.asList("a", "test_group");
// 忽略表前綴,如忽略a開頭的數(shù)據(jù)庫表
List<String> ignorePrefix = Arrays.asList("a", "t");
// 忽略表后綴
List<String> ignoreSuffix = Arrays.asList("_test", "czb_");
return ProcessConfig.builder()
//根據(jù)名稱指定表生成
.designatedTableName(Arrays.asList("fire_user"))
//根據(jù)表前綴生成
.designatedTablePrefix(new ArrayList<>())
//根據(jù)表后綴生成
.designatedTableSuffix(new ArrayList<>())
//忽略表名
.ignoreTableName(ignoreTableName)
//忽略表前綴
.ignoreTablePrefix(ignorePrefix)
//忽略表后綴
.ignoreTableSuffix(ignoreSuffix).build();
}
}
screw
有
HTML
、DOC
、MD
三種格式的文檔。
代碼中的修改
.fileType(EngineFileType.HTML)
或者pom
文件
<fileType>MD</fileType>
DOC
文檔樣式
HTML
文檔樣式
MD
文檔樣式
“怎么一鍵生成數(shù)據(jù)庫文檔”的內(nèi)容就介紹到這里了,感謝大家的閱讀。如果想了解更多行業(yè)相關(guān)的知識(shí)可以關(guān)注億速云網(wǎng)站,小編將為大家輸出更多高質(zhì)量的實(shí)用文章!
免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如果涉及侵權(quán)請(qǐng)聯(lián)系站長郵箱:is@yisu.com進(jìn)行舉報(bào),并提供相關(guān)證據(jù),一經(jīng)查實(shí),將立刻刪除涉嫌侵權(quán)內(nèi)容。