很多時(shí)候,我們?yōu)榱酥泵炮s項(xiàng)目進(jìn)度,很容易忽略整理文檔這件事
某一天,領(lǐng)導(dǎo)心血來潮,要搞一次突擊檢查, 想看看我們的數(shù)據(jù)庫設(shè)計(jì)的是否規(guī)范, 但他又不想親自去數(shù)據(jù)庫查驗(yàn)(畢竟這么大領(lǐng)導(dǎo))
那么,我們該怎么辦?
第一種方法:離職,世界那么大,我想去看看(我相信一般人不會(huì)這么做)
也許你可以試試下面這種方法
此方法大概屬于奇技淫巧,建議在工作中多用
基本思路就是通過Java代碼自動(dòng)生成數(shù)據(jù)庫表結(jié)構(gòu)文檔
在Java中正好有個(gè)包可以實(shí)現(xiàn)這個(gè)功能
- POM文件引入相關(guān)包
...
<dependency>
<groupId>org.freemarker</groupId>
<artifactId>freemarker</artifactId>
<version>2.3.30</version>
</dependency>
<dependency>
<groupId>cn.smallbun.screw</groupId>
<artifactId>screw-core</artifactId>
<version>1.0.3</version>
</dependency>
- 配置數(shù)據(jù)庫
spring:
datasource:
url: jdbc:mysql://localhost:3306/xxx?useUnicode=true&characterEncoding=utf-8&serverTimezone=Asia/Shanghai&useSSL=false&allowMultiQueries=true&allowPublicKeyRetrieval=true
username: root
password: xxx
driver-class-name: com.mysql.cj.jdbc.Driver
- 編寫轉(zhuǎn)換代碼
package com.example.createdoc;
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.assertj.core.util.Lists;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.junit4.SpringRunner;
import javax.annotation.Resource;
import javax.sql.DataSource;
/**
* <h1>數(shù)據(jù)庫表文檔生成</h1>
* */
@SpringBootTest
@RunWith(SpringRunner.class)
public class Table2DocTest {
@Resource
private DataSource dataSource;
@Test
public void buildDBDoc() {
EngineConfig engineConfig = EngineConfig.builder()
// 生成文件路徑
.fileOutputDir("D:\\temp")
.openOutputDir(false)
// 文件類型 支持 world,html, md
.fileType(EngineFileType.WORD)
.produceType(EngineTemplateType.freemarker).build();
// 生成文檔配置, 包含自定義版本號(hào)、描述等等
Configuration config = Configuration.builder()
.version("1.0.0")
.description("瞎編數(shù)據(jù)庫")
.dataSource(dataSource)
.engineConfig(engineConfig)
.produceConfig(
// 表的生成規(guī)則和忽略規(guī)則在這里配置
ProcessConfig.builder()
.designatedTableName(Lists.newArrayList())
.designatedTablePrefix(Lists.newArrayList())
.designatedTableSuffix(Lists.newArrayList())
.ignoreTableName(Lists.newArrayList())
.ignoreTablePrefix(Lists.newArrayList())
.ignoreTableSuffix(Lists.newArrayList())
.build()
).build();
// 執(zhí)行生成
new DocumentationExecute(config).execute();
}
}
我們用的這個(gè)組件 screw 可以實(shí)現(xiàn)生成doc、md、html類型的文檔,生成的目錄在代碼中可配置文章來源:http://www.zghlxwxcb.cn/news/detail-711854.html
就這樣,該下班下班,該下課下課文章來源地址http://www.zghlxwxcb.cn/news/detail-711854.html
到了這里,關(guān)于領(lǐng)導(dǎo)臨時(shí)要數(shù)據(jù)庫文檔怎么辦?的文章就介紹完了。如果您還想了解更多內(nèi)容,請?jiān)谟疑辖撬阉鱐OY模板網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關(guān)文章,希望大家以后多多支持TOY模板網(wǎng)!