<kbd id="afajh"><form id="afajh"></form></kbd>
<strong id="afajh"><dl id="afajh"></dl></strong>
    <del id="afajh"><form id="afajh"></form></del>
        1. <th id="afajh"><progress id="afajh"></progress></th>
          <b id="afajh"><abbr id="afajh"></abbr></b>
          <th id="afajh"><progress id="afajh"></progress></th>

          實(shí)用!一鍵生成數(shù)據(jù)庫文檔,堪稱數(shù)據(jù)庫界的Swagger

          共 4328字,需瀏覽 9分鐘

           ·

          2020-08-08 19:41

          最近部門訂單業(yè)務(wù)調(diào)整,收攏其他業(yè)務(wù)線的下單入口,做個(gè)統(tǒng)一大訂單平臺(tái)。需要梳理各業(yè)務(wù)線的數(shù)據(jù)表,但每個(gè)業(yè)務(wù)線庫都有近百張和訂單相關(guān)的表,挨個(gè)表一個(gè)一個(gè)字段的弄腦瓜子嗡嗡的。
          為了不重復(fù) CV 操作,抱著一絲希望開始在GitHub里找,看看有沒有什么工具可以用,結(jié)果就真的發(fā)現(xiàn)了寶藏,screw(螺絲釘),居然可以生成數(shù)據(jù)庫文檔,優(yōu)秀啊~。
          數(shù)據(jù)庫文檔圖

          一、數(shù)據(jù)庫支持

            MySQL

            MariaDB

            TIDB

            Oracle

            SqlServer

            PostgreSQL

            Cache DB

          二、配置

          1、pom文件

          引入screw核心包,HikariCP數(shù)據(jù)庫連接池,HikariCP號(hào)稱性能最出色的數(shù)據(jù)庫連接池。

          <dependency>
          ????<groupId>cn.smallbun.screwgroupId>

          ????<artifactId>screw-coreartifactId>

          ????<version>1.0.3version>
          dependency>


          <dependency>
          ????<groupId>com.zaxxergroupId>

          ????<artifactId>HikariCPartifactId>
          ????<version>3.4.5version>
          dependency>


          <dependency>
          ????<groupId>mysqlgroupId>

          ????<artifactId>mysql-connector-javaartifactId>
          ????<version>8.0.20version>
          dependency>

          2、配置數(shù)據(jù)源

          配置數(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?

          3、screw 核心配置

          screw有兩種執(zhí)行方式,第一種是pom文件配置,另一種是代碼執(zhí)行。
          ?
          ????<plugins>
          ????????<plugin>
          ????????????<groupId>org.springframework.bootgroupId>

          ????????????<artifactId>spring-boot-maven-pluginartifactId>

          ????????plugin>
          ????????<plugin>
          ????????????<groupId>cn.smallbun.screwgroupId>
          ????????????<artifactId>screw-maven-pluginartifactId>
          ????????????<version>1.0.3version>
          ????????????<dependencies>
          ????????????????
          ????????????????<dependency>
          ????????????????????<groupId>com.zaxxergroupId>
          ????????????????????<artifactId>HikariCPartifactId>
          ????????????????????<version>3.4.5version>
          ????????????????dependency>
          ????????????????
          ????????????????<dependency>
          ????????????????????<groupId>mysqlgroupId>
          ????????????????????<artifactId>mysql-connector-javaartifactId>
          ????????????????????<version>8.0.20version>
          ????????????????dependency>
          ????????????dependencies>
          ????????????<configuration>
          ????????????????
          ????????????????<username>rootusername>
          ????????????????
          ????????????????<password>123456password>
          ????????????????
          ????????????????<driverClassName>com.mysql.cj.jdbc.DriverdriverClassName>
          ????????????????
          ????????????????<jdbcUrl>jdbc:mysql://41.92.6.5:3306/firejdbcUrl>
          ????????????????
          ????????????????<fileType>HTMLfileType>
          ????????????????
          ????????????????<openOutputDir>falseopenOutputDir>
          ????????????????
          ????????????????<produceType>freemarkerproduceType>
          ????????????????
          ????????????????
          ????????????????
          ????????????????<description>數(shù)據(jù)庫文檔生成description>
          ????????????????
          ????????????????<version>${project.version}version>
          ????????????????
          ????????????????<title>fire數(shù)據(jù)庫文檔title>
          ????????????configuration>
          ????????????<executions>
          ????????????????<execution>
          ????????????????????<phase>compilephase>
          ????????????????????<goals>
          ????????????????????????<goal>rungoal>
          ????????????????????goals>
          ????????????????execution>
          ????????????executions>
          ????????plugin>
          ????plugins>
          </build>
          配置完以后在?maven project->screw?雙擊執(zhí)行ok。
          運(yùn)行方式
          代碼生成方式也非常簡單。
          @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();
          ????}
          }

          4、文檔格式

          screw?有?HTMLDOCMD?三種格式的文檔。
          代碼中的修改
          .fileType(EngineFileType.HTML)
          或者pom文件
          MD</fileType>
          DOC文檔樣式
          DOC文檔
          HTML文檔樣式
          HTML文檔
          MD文檔樣式
          MD文檔


          demo 的 GitHub 地址:
          https://github.com/chengxy-nds/Springboot-Notebook/tree/master/springboot-database-doc

          推薦閱讀:


          喜歡我可以給我設(shè)為星標(biāo)哦

          好文章,我“在看”
          瀏覽 44
          點(diǎn)贊
          評(píng)論
          收藏
          分享

          手機(jī)掃一掃分享

          分享
          舉報(bào)
          評(píng)論
          圖片
          表情
          推薦
          點(diǎn)贊
          評(píng)論
          收藏
          分享

          手機(jī)掃一掃分享

          分享
          舉報(bào)
          <kbd id="afajh"><form id="afajh"></form></kbd>
          <strong id="afajh"><dl id="afajh"></dl></strong>
            <del id="afajh"><form id="afajh"></form></del>
                1. <th id="afajh"><progress id="afajh"></progress></th>
                  <b id="afajh"><abbr id="afajh"></abbr></b>
                  <th id="afajh"><progress id="afajh"></progress></th>
                  我爱操逼网 | 91国产在线自在拍 | 怡红院黄片| 久热国产在线 | 东京热国产 |