SpringBoot 集成 screw 一键生成数据库文档
今天闲逛 github,发现一个数据库生成文档的工具,所以就尝试着使用了工具,确实生成效果还是挺不错的
-
SpringBoot 集成 screw 一键生成数据库文档源码
1、screw 特点
-
简洁、轻量、设计良好 -
多数据库支持 -
多种格式文档 -
灵活扩展 -
支持自定义模板
2、数据库支持
-
[x] MySQL -
[x] MariaDB -
[x] TIDB -
[x] Oracle -
[x] SqlServer -
[x] PostgreSQL -
[x] Cache DB(2016) -
[ ] H2 (开发中) -
[ ] DB2 (开发中) -
[ ] HSQL (开发中) -
[ ] SQLite(开发中) -
[ ] 瀚高(开发中) -
[ ] 达梦 (开发中) -
[ ] 虚谷 (开发中) -
[ ] 人大金仓(开发中)
3、文档生成支持
-
[x] html -
[x] word -
[x] markdown
4、使用方法
项目中增加依赖,如果有数据源的,可以使用你自己的数据源就可以了
<dependency>
<groupId>com.zaxxer</groupId>
<artifactId>HikariCP</artifactId>
<version>3.4.5</version>
</dependency>
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>5.1.47</version>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>cn.smallbun.screw</groupId>
<artifactId>screw-core</artifactId>
<version>1.0.5</version>
</dependency>
然后写一个 Main 方法,修改数据库地址、账号、密码、表配置等,直接运行即可生成
package cn.tellsea.test;
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 com.zaxxer.hikari.HikariConfig;
import com.zaxxer.hikari.HikariDataSource;
import javax.sql.DataSource;
import java.util.ArrayList;
/**
* SpringBoot 集成 screw 一键生成数据库文档
*
* @author Tellsea
* @date 2022/3/16
*/
public class MainTest {
public static void main(String[] args) {
documentGeneration();
}
/**
* 文档生成
*/
public static void documentGeneration() {
//数据源
HikariConfig hikariConfig = new HikariConfig();
hikariConfig.setDriverClassName("com.mysql.jdbc.Driver");
hikariConfig.setJdbcUrl("jdbc:mysql://127.0.0.1:3306/project-service?useUnicode=true&characterEncoding=UTF-8");
hikariConfig.setUsername("root");
hikariConfig.setPassword("123456");
//设置可以获取tables remarks信息
hikariConfig.addDataSourceProperty("useInformationSchema", "true");
hikariConfig.setMinimumIdle(2);
hikariConfig.setMaximumPoolSize(5);
DataSource dataSource = new HikariDataSource(hikariConfig);
//生成配置
EngineConfig engineConfig = EngineConfig.builder()
//生成文件路径
.fileOutputDir("D:\test")
//打开目录
.openOutputDir(true)
//文件类型
.fileType(EngineFileType.HTML)
//生成模板实现
.produceType(EngineTemplateType.freemarker)
//自定义文件名称
.fileName("自定义文件名称").build();
//忽略表
ArrayList<String> ignoreTableName = new ArrayList<>();
ignoreTableName.add("test_user");
ignoreTableName.add("test_group");
//忽略表前缀
ArrayList<String> ignorePrefix = new ArrayList<>();
ignorePrefix.add("test_");
//忽略表后缀
ArrayList<String> ignoreSuffix = new ArrayList<>();
ignoreSuffix.add("_test");
ProcessConfig processConfig = ProcessConfig.builder()
//指定生成逻辑、当存在指定表、指定表前缀、指定表后缀时,将生成指定表,其余表不生成、并跳过忽略表配置
//根据名称指定表生成
.designatedTableName(new ArrayList<>())
//根据表前缀生成
.designatedTablePrefix(new ArrayList<>())
//根据表后缀生成
.designatedTableSuffix(new ArrayList<>())
//忽略表名
.ignoreTableName(ignoreTableName)
//忽略表前缀
.ignoreTablePrefix(ignorePrefix)
//忽略表后缀
.ignoreTableSuffix(ignoreSuffix).build();
//配置
Configuration config = Configuration.builder()
//版本
.version("1.0.0")
//描述
.description("数据库设计文档生成")
//数据源
.dataSource(dataSource)
//生成配置
.engineConfig(engineConfig)
//生成配置
.produceConfig(processConfig)
.build();
//执行生成
new DocumentationExecute(config).execute();
}
}
微信公众号
原文始发于微信公众号(花海里):【SpringBoot学习】37、SpringBoot 集成 screw 一键生成数据库文档
版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 举报,一经查实,本站将立刻删除。
文章由极客之音整理,本文链接:https://www.bmabk.com/index.php/post/69608.html