当前位置:网站首页>Generate database documents with one click, which can be called swagger in the database industry
Generate database documents with one click, which can be called swagger in the database industry
2022-07-02 08:13:00 【Java notes shrimp】
Click on the official account , utilize Fragment time to learn
brief introduction
In enterprise development 、 We often have time to write database table structure documents , Since working , I've been to several enterprises , About database table structure document status : Or not 、 Or there is 、 But it's all handwritten 、 Later operation and maintenance development , It needs to be maintained manually into the document , It's very complicated 、 If you forget a maintenance 、 It will cause a lot of trouble to the future work 、 Virtually created a lot of holes for themselves and future generations , So I came up with the idea of writing a plug-in tool by myself
But because I didn't have many attainments in program design in the early stage , And the ability is low , Having an idea doesn't work well , With the increase of work experience , And the constant reserve of knowledge , Finally in the 2020 Year of 3 Start writing in mid June ,4 The first edition will be completed in the first ten days of this month , Want to improve almost in open source , But because the work is too busy , Lack of spare time , Not being perfected , here we are 6 Month due to work reasons 、 Design and change databases frequently 、 Often use this plug-in written by yourself 、 Saved a lot of time , Solved a lot of problems , There is only a little spare time 、 Prepare for open source , On 2020 year 6 month 22 Japan , Open source , Welcome to use 、 Suggest 、 And contribute .
About the name , It's too hard to think of one , Fortunately, my clever little brain was inspired , How to highlight its small , But important ? I have learned Lei Feng's screw spirit since I was a child , From Lei Feng's diary : Although it's a small screw , It's a tiny pinion , But without it , Then the whole machine won't work , Let's just say it's missing , Even a small screw is not tightened , A small gear wheel is slightly damaged , It is also necessary to break down the operation of the machine ...,
I feel like I wrote this tool , It means a lot , Small as it is 、 But it's not enough without it in development , So it was named screw( screws ).
characteristic
concise 、 Light weight 、 Well designed
Multi database support
Multiple format documents
Flexible expansion
Support custom templates
Database support
[x] MySQL
[x] MariaDB
[x] TIDB
[x] Oracle
[x] SqlServer
[x] PostgreSQL
[x] Cache DB(2016)
[ ] H2 ( In development )
[ ] DB2 ( In development )
[ ] HSQL ( In development )
[ ] SQLite( In development )
[ ] Hangao ( In development )
[ ] Reach a dream ( In development )
[ ] Empty valley ( In development )
[ ] Renmin Jincang ( In development )
Document generation support
[x] html
[x] word
[x] markdown
Document screenshot
html


word

markdwon


Usage mode
The ordinary way
Introduce dependencies
<dependency>
<groupId>cn.smallbun.screw</groupId>
<artifactId>screw-core</artifactId>
<version>${lastVersion}</version>
</dependency>
Write code
/**
* Document generation
*/
void documentGeneration() {
// data source
HikariConfig hikariConfig = new HikariConfig();
hikariConfig.setDriverClassName("com.mysql.cj.jdbc.Driver");
hikariConfig.setJdbcUrl("jdbc:mysql://127.0.0.1:3306/database");
hikariConfig.setUsername("root");
hikariConfig.setPassword("password");
// Set to get tables remarks Information
hikariConfig.addDataSourceProperty("useInformationSchema", "true");
hikariConfig.setMinimumIdle(2);
hikariConfig.setMaximumPoolSize(5);
DataSource dataSource = new HikariDataSource(hikariConfig);
// Generate configuration
EngineConfig engineConfig = EngineConfig.builder()
// Generate file path
.fileOutputDir(fileOutputDir)
// Open Directory
.openOutputDir(true)
// file type
.fileType(EngineFileType.HTML)
// Generate template implementation
.produceType(EngineTemplateType.freemarker)
// Custom file name
.fileName(" Custom file name ").build();
// Ignore table
ArrayList<String> ignoreTableName = new ArrayList<>();
ignoreTableName.add("test_user");
ignoreTableName.add("test_group");
// Ignore table prefix
ArrayList<String> ignorePrefix = new ArrayList<>();
ignorePrefix.add("test_");
// Ignore table suffix
ArrayList<String> ignoreSuffix = new ArrayList<>();
ignoreSuffix.add("_test");
ProcessConfig processConfig = ProcessConfig.builder()
// Specify the generation logic 、 When there is a specified table 、 Specify table prefix 、 When specifying the table suffix , The specified table will be generated , The rest of the tables do not generate 、 And skip ignoring table configuration
// Specify a table by name to generate
.designatedTableName(new ArrayList<>())
// Generate according to the table prefix
.designatedTablePrefix(new ArrayList<>())
// Generate from table suffix
.designatedTableSuffix(new ArrayList<>())
// Ignore table name
.ignoreTableName(ignoreTableName)
// Ignore table prefix
.ignoreTablePrefix(ignorePrefix)
// Ignore table suffix
.ignoreTableSuffix(ignoreSuffix).build();
// To configure
Configuration config = Configuration.builder()
// edition
.version("1.0.0")
// describe
.description(" Database design document generation ")
// data source
.dataSource(dataSource)
// Generate configuration
.engineConfig(engineConfig)
// Generate configuration
.produceConfig(processConfig)
.build();
// Perform build
new DocumentationExecute(config).execute();
}
Maven plug-in unit
<build>
<plugins>
<plugin>
<groupId>cn.smallbun.screw</groupId>
<artifactId>screw-maven-plugin</artifactId>
<version>${lastVersion}</version>
<dependencies>
<!-- HikariCP -->
<dependency>
<groupId>com.zaxxer</groupId>
<artifactId>HikariCP</artifactId>
<version>3.4.5</version>
</dependency>
<!--mysql driver-->
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>8.0.20</version>
</dependency>
</dependencies>
<configuration>
<!--username-->
<username>root</username>
<!--password-->
<password>password</password>
<!--driver-->
<driverClassName>com.mysql.cj.jdbc.Driver</driverClassName>
<!--jdbc url-->
<jdbcUrl>jdbc:mysql://127.0.0.1:3306/xxxx</jdbcUrl>
<!-- Make file type -->
<fileType>HTML</fileType>
<!-- Open the file output directory -->
<openOutputDir>false</openOutputDir>
<!-- Generate template -->
<produceType>freemarker</produceType>
<!-- Document name It's empty time : Will adopt [ Database name - describe - Version number ] As a document name -->
<fileName> Test document name </fileName>
<!-- describe -->
<description> Database document generation </description>
<!-- edition -->
<version>${project.version}</version>
<!-- title -->
<title> Database documents </title>
</configuration>
<executions>
<execution>
<phase>compile</phase>
<goals>
<goal>run</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
Extension module
pojo Generating function
Function introduction
pojo The generation function is based on screw Extended extension module , At present, it is in the state of preliminary development . In daily development , After demand analysis 、 After modeling , You often create tables in the database first , Secondly, we are developing the code .
that pojo At this stage, the generation function can help you save some repetitive work . Use pojo The generation function can directly generate the corresponding data according to the database java pojo object . This allows subsequent modifications , Development will be very convenient .
Database support
[x] MySQL
Usage mode
Introduce dependencies
<dependency>
<groupId>cn.smallbun.screw</groupId>
<artifactId>screw-extension</artifactId>
<version>${lastVersion}</version>
</dependency>
Write code
/**
* pojo Generate
*/
void pojoGeneration() {
// data source
HikariConfig hikariConfig = new HikariConfig();
hikariConfig.setDriverClassName("com.mysql.cj.jdbc.Driver");
hikariConfig.setJdbcUrl("jdbc:mysql://127.0.0.1:3306/screw");
hikariConfig.setUsername("screw");
hikariConfig.setPassword("screw");
// Set to get tables remarks Information
hikariConfig.addDataSourceProperty("useInformationSchema", "true");
hikariConfig.setMinimumIdle(2);
hikariConfig.setMaximumPoolSize(5);
DataSource dataSource = new HikariDataSource(hikariConfig);
ProcessConfig processConfig = ProcessConfig.builder()
// Specify the generation logic 、 When there is a specified table 、 Specify table prefix 、 When specifying the table suffix , The specified table will be generated , The rest of the tables do not generate 、 And skip ignoring table configuration
// Specify a table by name to generate
.designatedTableName(new ArrayList<>())
// Generate according to the table prefix
.designatedTablePrefix(new ArrayList<>())
// Generate from table suffix
.designatedTableSuffix(new ArrayList<>()).build();
// Set up to generate pojo Related configuration
PojoConfiguration config = new PojoConfiguration();
// Set the file storage path
config.setPath("/cn/smallbun/screw/");
// Set package name
config.setPackageName("cn.smallbun.screw");
// Set whether to use lombok
config.setUseLombok(false);
// Set data source
config.setDataSource(dataSource);
// Set naming policy
config.setNameStrategy(new HumpNameStrategy());
// Set table filtering logic
config.setProcessConfig(processConfig);
// Perform build
new PojoExecute(config).execute();
}
common problem
The generated document is garbled ?
MySQL:URL Join in
?characterEncoding=UTF-8
.Caused by: java.lang.NoSuchFieldError: VERSION_2_3_30?
Inspection items
freemarker
rely on , This is because the version is too low , Upgrade to2.3.30
that will do .java.lang.AbstractMethodError: oracle.jdbc.driver.T4CConnection.getSchema()Ljava/lang/String;
This is because oracle The driver version is too low , Delete or mask the current driver version , Add and upgrade the driver to the following version :
<dependency>
<groupId>com.oracle.ojdbc</groupId>
<artifactId>ojdbc8</artifactId>
<version>19.3.0.0</version>
</dependency>
<dependency>
<groupId>cn.easyproject</groupId>
<artifactId>orai18n</artifactId>
<version>12.1.0.2.0</version>
</dependency>
MySQL The database table and column fields are described 、 The generated document does not explain ?
URL Link join
useInformationSchema=true
that will do .java.lang.AbstractMethodError: com.mysql.jdbc.JDBC4Connection.getSchema()Ljava/lang/String;
This is because mysql The driver version is too low , upgrade mysql The driver version is the latest .
Project address
https://gitee.com/leshalv/screw
recommend :
Main stream Java Advanced technology ( Learning material sharing )
PS: Because the official account platform changed the push rules. , If you don't want to miss the content , Remember to click after reading “ Looking at ”, Add one “ Star standard ”, In this way, each new article push will appear in your subscription list for the first time . spot “ Looking at ” Support us !
边栏推荐
- Force buckle method summary: sliding window
- Deep understanding of JVM
- Business architecture diagram
- 关于原型图的深入理解
- On the back door of deep learning model
- Simply test the two different data transmission methods of content length and chunked
- 力扣方法总结:滑动窗口
- In the era of short video, how to ensure that works are more popular?
- Global and Chinese markets for magnetic resonance imaging (MRI) transmission 2022-2028: Research Report on technology, participants, trends, market size and share
- Use of OpenCV 6.4 median filter
猜你喜欢
Matlab数学建模工具
Open3d learning note 4 [surface reconstruction]
利用Transformer来进行目标检测和语义分割
Using transformer for object detection and semantic segmentation
Where do you find the materials for those articles that have read 10000?
OpenCV3 6.2 低通滤波器的使用
浅谈深度学习模型中的后门
针对语义分割的真实世界的对抗样本攻击
乐理基础(简述)
应对长尾分布的目标检测 -- Balanced Group Softmax
随机推荐
力扣方法总结:查找类
WCF更新服务引用报错的原因之一
Comparison between setTimeout and requestanimationframe (page refresh)
Introduction to parameters of CarSim pavement 3D shape file
图像增强的几个方法以及Matlab代码
Fundamentals of music theory (brief introduction)
针对tqdm和print的顺序问题
简易打包工具的安装与使用
Global and Chinese markets for conventional rubber track 2022-2028: Research Report on technology, participants, trends, market size and share
常量指针和指针常量
It's great to save 10000 pictures of girls
利用Transformer来进行目标检测和语义分割
Cvpr19 deep stacked hierarchical multi patch network for image deblurring paper reproduction
力扣每日一题刷题总结:字符串篇(持续更新)
Brief introduction of prompt paradigm
Programmers can only be 35? The 74 year old programmer in the United States has been programming for 57 years and has not retired
Global and Chinese market of tillage finishing machines 2022-2028: Research Report on technology, participants, trends, market size and share
E-R画图明确内容
11月24号,我们为“满月”庆祝
Erase method in string