2 Star 3 Fork 1

coderush / dumpling

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
贡献代码
同步代码
取消
提示: 由于 Git 不支持空文件夾,创建文件夹后会生成空的 .keep 文件
Loading...
README
MIT

项目名:饺子

鉴于服务的公司内部confluence中的数据字典,大多数都是从数据库客户端copy出来的DDL文件。

对于开发人员说,编写数据字典需要把一张张表的DDL内容copy到confluence页面里,比较繁琐和浪费时间。

因此本人花了两个多月休息时间,编写了一个可以生成html,markdown,word,excel四种格式数据字典的maven插件

欢迎试用~

ps:由于本人只熟悉mysql数据库,所以该插件目前不支持mysql以外的数据库,欢迎好心人提oracle,sqlserver等数据库的PR,谢谢啦~

技术栈

  • java1.8
  • junit5.7
  • SPI
  • lambda
  • freeMarker
  • velocity

数据库支持

  • MySQL

文档生成支持

  • html
  • word
  • excel
  • markdown

使用方式

普通方式

  • 引入依赖

<dependency>
    <groupId>com.wujunshen.dumpling</groupId>
    <artifactId>dumpling-core</artifactId>
    <version>${latestVersion}</version>
</dependency>
  • 编写代码
    /**
    * 获取数据源
    */
    public DataSource getDataSource() {
        File path =
            FileUtils.getFileByPath(
                FILE_OUTPUT_DIR + "/src/test/resources/properties/mysql.properties");
        Properties properties = new Properties();
        FileInputStream inputStream = new FileInputStream(Objects.requireNonNull(path));
        properties.load(inputStream);

        // 数据源
        HikariConfig config = new HikariConfig();
        config.setDriverClassName(getDriver(properties));
        config.setJdbcUrl(getUrl(properties));
        config.setUsername(getUserName(properties));
        config.setPassword(getPassword(properties));
        // 设置可以获取tables备注信息
        config.addDataSourceProperty("useInformationSchema", "true");
        config.setMinimumIdle(2);
        config.setMaximumPoolSize(5);
        return new HikariDataSource(config);
    }
  
    /**
    * 获取生成引擎配置
    */
    public EngineConfig getEngineConfig(
      EngineFileType engineFileType, EngineTemplateType engineTemplateType) {
      
    return EngineConfig.builder()
        // 生成文件路径
        .fileOutputDir(FILE_OUTPUT_DIR)
        // 打开目录
        .openOutputDir(true)
        // 文件类型
        .fileType(engineFileType)
        // 生成模板实现
        .produceType(engineTemplateType)
        .build();
    }
    
  /**
   * 配置
   *
   * @param engineConfig EngineConfig
   * @return Configuration
   */
  public Configuration config(EngineConfig engineConfig) {
    return Configuration.builder()
        // 版本
        .version("1.0")
        // 描述
        .description("数据字典")
        // 数据源
        .dataSource(getDataSource())
        // 生成配置
        .engineConfig(engineConfig)
        // 生成配置
        .produceConfig(setIgnoreSetting())
        .build();
  }
  
  /**
   * 设置忽略表配置
   *
   * @return ProcessConfig
   */
  public ProcessConfig setIgnoreSetting() {
    List<String> ignoreTableName = new ArrayList<>();
    ignoreTableName.add("test");
    // 忽略表前缀
    List<String> ignorePrefix = new ArrayList<>();
    ignorePrefix.add("test");
    // 忽略表后缀
    List<String> ignoreSuffix = new ArrayList<>();
    ignoreSuffix.add("test");
    return ProcessConfig.builder()
        // 忽略表名
        .ignoreTableName(ignoreTableName)
        // 忽略表前缀
        .ignoreTablePrefix(ignorePrefix)
        // 忽略表后缀
        .ignoreTableSuffix(ignoreSuffix)
        .build();
  }

  /**
   * 执行数据字典生成的单元测试方法
   *
   */
  @Test
  @Order(0)
  @DisplayName("生成数据字典-md-freemarker")
  void mdFreemarker() {
    EngineConfig engineConfig = getEngineConfig(MD, FREEMARKER);

    Configuration config = config(engineConfig);

    execute(config);
  }

Maven 插件

<build>
    <plugins>
        <plugin>
            <groupId>com.wujunshen.dumpling</groupId>
            <artifactId>dumpling-maven-plugin</artifactId>
            <version>${latestVersion}</version>
            <dependencies>
                <dependency>
                    <groupId>com.zaxxer</groupId>
                    <artifactId>HikariCP</artifactId>
                    <version>3.4.5</version>
                </dependency>
                <dependency>
                    <groupId>mysql</groupId>
                    <artifactId>mysql-connector-java</artifactId>
                    <version>8.0.20</version>
                </dependency>
            </dependencies>
            <configuration>
                <username>username</username>
                <password>password</password>
                <driverClassName>com.mysql.cj.jdbc.Driver</driverClassName>
                <jdbcUrl>jdbc:mysql://localhost:3306/xxx?useUnicode=true&characterEncoding=utf-8&useSSL=true&serverTimezone=GMT%2B8&useInformationSchema=true</jdbcUrl>
                <!--数据字典文档格式,包括html、doc、xls、md四种格式。默认html-->
                <fileType>html</fileType>
                <!--是否需要打开已生成的数据字典文档所在的目录,true为打开,false为不打开。默认false-->
                <openOutputDir>false</openOutputDir>
                <!--数据字典文档的内容模板类型,有freemarker、velocity两种。默认freemarker-->
                <produceType>freemarker</produceType>
                <!--文档名为空时:采用[数据库名称-描述-版本号]作为文档名-->
                <fileName>生成的文档名</fileName>
                <!--描述-->
                <description>数据字典</description>
                <!--版本-->
                <version>${project.version}</version>
                <!--标题-->
                <title>数据字典</title>
            </configuration>
            <executions>
                <execution>
                    <phase>compile</phase>
                    <goals>
                        <goal>run</goal>
                    </goals>
                </execution>
            </executions>
        </plugin>
    </plugins>
</build>

生成效果图

html

输入图片说明

输入图片说明

excel

输入图片说明

输入图片说明

word

输入图片说明

输入图片说明

markdown

输入图片说明

输入图片说明

MIT License Copyright (c) 2021 coderush Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

简介

饺子-数据字典文档生成工具 展开 收起
Java
MIT
取消

发行版

暂无发行版

贡献者

全部

近期动态

加载更多
不能加载更多了
Java
1
https://gitee.com/darkranger/dumpling.git
git@gitee.com:darkranger/dumpling.git
darkranger
dumpling
dumpling
master

搜索帮助