生成数据库文档 —— Spring Boot + Screw
2024-10-21 07:46:29
1、创建一个SpringBoot项目(本人使用的是IntelliJ IDEA 2020.1 x64)
- 最佳简单的项目配置如下:
2、添加相关依赖
<!--screw依赖-->
<dependency>
<groupId>cn.smallbun.screw</groupId>
<artifactId>screw-core</artifactId>
<version>1.0.5</version>
</dependency>
<!--解决连接oracle中文乱码-->
<dependency>
<groupId>cn.easyproject</groupId>
<artifactId>orai18n</artifactId>
<version>12.1.0.2.0</version>
</dependency>
3、连接数据库配置
#screw支持的数据库:MySQL、MariaDB、TIDB、Oracle、SqlServer、PostgreSQL、Cache DB(2016)
spring.datasource.url=jdbc:oracle:thin:@自填服务器地址:1521:库名
spring.datasource.username=XXX
spring.datasource.password=XXX
spring.datasource.xa.properties.useInformationSchema=true
4、脚本主要内容
- 创建一个test类运行即可,代码如下:
package com.sinby.demo;
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.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.context.ApplicationContext;
import javax.sql.DataSource;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
@SpringBootTest
class DemoApplicationTests {
@Autowired
ApplicationContext applicationContext;
@Test
void contextLoads() {
DataSource dataSourceMysql = applicationContext.getBean(DataSource.class);
// 生成文件配置
EngineConfig engineConfig = EngineConfig.builder()
// 生成文件路径(可自定义)
.fileOutputDir("F:/XXX")
// 打开目录
.openOutputDir(false)
//生成文件名(可自定义)
.fileName("tablefile")
// 文件类型 .HTML .WORD .MARKDOWN
.fileType(EngineFileType.WORD)
// 生成模板实现
.produceType(EngineTemplateType.freemarker)
.build();
// 生成文档配置(包含以下自定义版本号、描述等配置连接)
Configuration config = Configuration.builder()
.version("1.0.1") //可自定义
.description("某某数据库中文文档") //可自定义
.dataSource(dataSourceMysql)
.engineConfig(engineConfig)
.produceConfig(getProcessConfig())
.build();
// 执行生成
new DocumentationExecute(config).execute();
}
/**
* 配置想要生成的表+ 配置想要忽略的表
* @return 生成表配置
*/
public static ProcessConfig getProcessConfig(){
// 忽略表名
List<String> ignoreTableName = Arrays.asList("aa","test_group");
// 忽略表前缀,如忽略a开头的数据库表
List<String> ignorePrefix = Arrays.asList("T_"); //,"t"
// 忽略表后缀
List<String> ignoreSuffix = Arrays.asList("_test","czb_");
return ProcessConfig.builder()
//根据名称指定表生成
.designatedTableName(new ArrayList<>())
//根据表前缀生成
.designatedTablePrefix(new ArrayList<>())
//根据表后缀生成
.designatedTableSuffix(new ArrayList<>())
//忽略表名
.ignoreTableName(ignoreTableName)
//忽略表前缀
.ignoreTablePrefix(ignorePrefix).build();
//忽略表后缀
.ignoreTableSuffix(ignoreSuffix).build();
}
}
5、参考
最新文章
- LCQCL
- hangfire+bootstrap ace 模板实现后台任务管理平台
- C语言用面向对象的思想写贪吃蛇
- Arduino101学习笔记(六)&mdash;&mdash; 高级IO
- (转载)iOS系统Crash文件分析方法
- hdu 5100 n*n棋盘放k*1长方条最多覆盖面积
- POJ2226 Muddy Fields 二分匹配 最小顶点覆盖 好题
- ganymed-ssh2使用
- 如何将CELERY放到后台执行?
- c语言的label后面不能直接跟变量申明
- js打开新的链接
- freemaker
- thinkphp 5.0 模块设计
- Struts(十五):主题
- Android图片setBackgroundResource和setImageResource的区别
- Codeforces 229E Gifts 概率dp (看题解)
- CSS文本超出指定行数省略显示
- 重写TreeMap的compare方法处理配置表
- T-SQL语句1
- 查询set、dict、dict.keys()的速度对比