相信小伙伴們在日常的開發中,調試代碼時,免不了經常修改代碼,這個時候,為了驗證效果,必須要重啟 Spring Boot 應用。 頻繁地重啟應用,導致開發效率降低,加班隨之而來。有沒有什麼辦法,能讓 Spring Boot 項目熱部署呢,從而不用每次都手點。答案是肯定的。 第一步:添加 spring- ...
很多時候,我們為了著急忙慌趕項目進度,很容易忽略整理文檔這件事
某一天,領導心血來潮,要搞一次突擊檢查, 想看看我們的資料庫設計的是否規範, 但他又不想親自去資料庫查驗(畢竟這麼大領導)
那麼,我們該怎麼辦?
第一種方法:離職,世界那麼大,我想去看看(我相信一般人不會這麼做)
也許你可以試試下麵這種方法
此方法大概屬於奇技淫巧,建議在工作中多用
基本思路就是通過Java代碼自動生成資料庫表結構文檔
在Java中正好有個包可以實現這個功能
- POM文件引入相關包
...
<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>
- 配置資料庫
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
- 編寫轉換代碼
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>資料庫表文檔生成</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();
// 生成文檔配置, 包含自定義版本號、描述等等
Configuration config = Configuration.builder()
.version("1.0.0")
.description("瞎編資料庫")
.dataSource(dataSource)
.engineConfig(engineConfig)
.produceConfig(
// 表的生成規則和忽略規則在這裡配置
ProcessConfig.builder()
.designatedTableName(Lists.newArrayList())
.designatedTablePrefix(Lists.newArrayList())
.designatedTableSuffix(Lists.newArrayList())
.ignoreTableName(Lists.newArrayList())
.ignoreTablePrefix(Lists.newArrayList())
.ignoreTableSuffix(Lists.newArrayList())
.build()
).build();
// 執行生成
new DocumentationExecute(config).execute();
}
}
我們用的這個組件 screw 可以實現生成doc、md、html類型的文檔,生成的目錄在代碼中可配置
就這樣,該下班下班,該下課下課
請關於一下啦^_^微信公眾號