当前位置: 首页 > article >正文

springboot+screw反向生成数据库说明文档

前言

       最近公司人员结构调整,被迫接受一位资深老哥哥的活,他也是悲催,太老实了,默默的干活老黄牛,不会叫。又没有山头,直接领导组长也是不给力。哎,哪里都有江湖,愿我码农儿女都能被善待!!!!
       今天要分享的是,搭建springboot项目,反向生成数据库表结构说明文档。


一、screw介绍

       不是大厂写的,是个人写的,但是不得不说,好使啊, 为爱发电。

二、使用步骤

1.新建一个空的springboot项目

       这个使用idea,选择springboot,下一步下一步就行。
我这里是maven项目,pom文件引入jar包。
我这里的整个pom.xml内容

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
	xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
	<modelVersion>4.0.0</modelVersion>
	<parent>
		<groupId>org.springframework.boot</groupId>
		<artifactId>spring-boot-starter-parent</artifactId>
		<version>3.3.3</version>
		<relativePath/> <!-- lookup parent from repository -->
	</parent>
	<groupId>com.easylinkin</groupId>
	<artifactId>my-screw</artifactId>
	<version>0.0.1-SNAPSHOT</version>
	<name>my-screw</name>
	<description>my-screw</description>
	<url/>
	<licenses>
		<license/>
	</licenses>
	<developers>
		<developer/>
	</developers>
	<scm>
		<connection/>
		<developerConnection/>
		<tag/>
		<url/>
	</scm>
	<properties>
		<java.version>17</java.version>
	</properties>
	<dependencies>
		<dependency>
			<groupId>org.springframework.boot</groupId>
			<artifactId>spring-boot-starter</artifactId>
		</dependency>

		<dependency>
			<groupId>org.springframework.boot</groupId>
			<artifactId>spring-boot-starter-test</artifactId>
			<scope>test</scope>
		</dependency>

		<dependency>
			<groupId>org.springframework.boot</groupId>
			<artifactId>spring-boot-starter-web</artifactId>
		</dependency>
		<dependency>
			<groupId>cn.smallbun.screw</groupId>
			<artifactId>screw-core</artifactId>
			<version>1.0.5</version>
		</dependency>
		<dependency>
			<groupId>com.mysql</groupId>
			<artifactId>mysql-connector-j</artifactId>
		</dependency>
		<dependency>
			<groupId>com.zaxxer</groupId>
			<artifactId>HikariCP</artifactId>
		</dependency>
		<dependency>
			<groupId>org.projectlombok</groupId>
			<artifactId>lombok</artifactId>
		</dependency>
	</dependencies>

	<build>
		<plugins>
			<plugin>
				<groupId>org.springframework.boot</groupId>
				<artifactId>spring-boot-maven-plugin</artifactId>
			</plugin>
		</plugins>
	</build>

</project>

2.生成文档的测试类

package com.easylinkin.myscrew;

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.HikariDataSource;
import lombok.extern.slf4j.Slf4j;
import org.junit.jupiter.api.Test;
import org.springframework.boot.test.context.SpringBootTest;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

@Slf4j
@SpringBootTest
class MyScrewApplicationTests {

	//@Test
	void contextLoads() {
	}

	/**
	 * 获取数据源配置
	 */
	@Test
	void generate() {
		log.info("开始生成数据库文档");
		String dbFilePath = "/Users/zwmac/work/ovu/数据库";
		// 生成文件配置
		EngineConfig engineConfig = EngineConfig.builder()
				// 生成文件路径,自己mac本地的地址,这里需要自己更换下路径
				.fileOutputDir(dbFilePath)
				// 打开目录
				.openOutputDir(false)
				// 文件类型 HTML/WORD/MD 三种格式
				.fileType(EngineFileType.WORD)
				// 生成模板实现
				.produceType(EngineTemplateType.freemarker).build();

		//数据库名称
		String[] dbNames = {"ovuhome"};
		for (String dbName : dbNames) {
			HikariDataSource hikariDataSource = new HikariDataSource();
			//设置数据库连接
			hikariDataSource.setJdbcUrl("jdbc:mysql://127.0.0.1:3306/" + dbName + "?characterEncoding=utf8&zeroDateTimeBehavior=convertToNull&useSSL=false&useJDBCCompliantTimezoneShift=true&useLegacyDatetimeCode=false&serverTimezone=GMT%2B8&allowMultiQueries=true&allowPublicKeyRetrieval=true");
			hikariDataSource.setUsername("root");
			hikariDataSource.setPassword("12345678");
			// 生成文档配置(包含以下自定义版本号、描述等配置连接)
			Configuration config = Configuration.builder()
					//文档版本号
					.version("1.0.1")
					//文档名称
					.description("公寓数据库设计文档")
					//数据源
					.dataSource(hikariDataSource)
					//生成引擎配置
					.engineConfig(engineConfig)
					//高级配置
					//.produceConfig(getProcessConfig())
					.build();

			// 执行生成
			new DocumentationExecute(config).execute();
		}
		log.info("生成数据库文档完成");
	}

	/**
	 * 配置想要生成的表+ 配置想要忽略的表
	 * @return 生成表配置
	 */
	public static ProcessConfig getProcessConfig(){
		// 忽略表名
		List<String> ignoreTableName = Arrays.asList("testa_testa","testb_testb");
		// 忽略表前缀
		List<String> ignorePrefix = Arrays.asList("testa","testb");
		// 忽略表后缀
		List<String> ignoreSuffix = Arrays.asList("_testa","_testb");
		return ProcessConfig.builder()
				//根据名称指定表生成 我需要生成所有表 这里暂时不设置
				.designatedTableName(new ArrayList<>())
				//根据表前缀生成 我需要生成所有表 这里暂时不设置
				.designatedTablePrefix(new ArrayList<>())
				//根据表后缀生成 我需要生成所有表 这里暂时不设置
				.designatedTableSuffix(new ArrayList<>())
				//忽略表名
				.ignoreTableName(ignoreTableName)
				//忽略表前缀
				.ignoreTablePrefix(ignorePrefix)
				//忽略表后缀
				.ignoreTableSuffix(ignoreSuffix).build();
	}

}

       测试类运行,就不说了,自己摸索摸索。

3.生成的word文档效果

在这里插入图片描述


总结

       接手的活就是三无项目,无测试、无需求、无文档,只有代码。到我这已经是第五手了,山头注意真害人,还限制人发展啊。愿我们码农儿女都能凭技术吃饭,扎扎实实的,少些勾心斗角。


http://www.kler.cn/news/310021.html

相关文章:

  • 【动态规划】
  • 23ai DGPDB,Oracle资源池战略的最后一块拼图
  • C++速通LeetCode简单第11题-对称二叉树
  • 【rust】rust条件编译
  • 【linux-Day3】linux的基本指令<中>
  • 打包部署若依(RuoYi)SpringBoot后端和Vue前端图文教程
  • pycv实时目标检测快速实现
  • 120页ppt丨集团公司战略规划内容、方法、步骤及战略规划案例研究
  • 分类预测|基于粒子群优化径向基神经网络的数据分类预测Matlab程序PSO-RBF 多特征输入多类别输出 含基础RBF程序
  • 【鸿蒙】HarmonyOS NEXT星河入门到实战8-自定义组件-组件通信
  • 江科大笔记—STM32课程简介
  • 基于SpringBoot+Vue+MySQL的家乡特色推荐系统
  • 英飞凌—TC377芯片详解(1)
  • npm包管理工具
  • UGit:腾讯自研的Git客户端新宠
  • Spring如何处理线程并发问题?
  • 传输层协议 —— UDP协议
  • LXDE lxpanel桌面环境中打开一个终端窗口 lxterminal
  • PHP 中传值与传引用的区别
  • 线程有哪几种状态?
  • web杂项
  • 腾讯云技术深度探索:构建高效云原生微服务架构
  • Java Stream API | Java Stream API 中 `filter()`的使用
  • TCP/IP Socket用于测试免费使用的服务器端
  • window下idea中scala的配置
  • web基础—dvwa靶场(五)File Upload
  • HarmonyOS开发之自定义构建函数
  • gi清除无用缓存
  • 【Elasticsearch系列】Elasticsearch中的分页
  • Python用TOPSIS熵权法重构粮食系统及期刊指标权重多属性决策MCDM研究|附数据代码