当前位置:网站首页>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 !
边栏推荐
- 图像增强的几个方法以及Matlab代码
- 乐理基础(简述)
- VS Code配置问题
- Summary of one question per day: stack and queue (continuously updated)
- Chinese garbled code under vscade
- Vs code configuration problem
- 联邦学习下的数据逆向攻击 -- GradInversion
- Force deduction method summary: find classes
- Opencv3 6.3 reduced pixel sampling with filters
- Go functions make, slice, append
猜你喜欢
On November 24, we celebrate the "full moon"
Embedding malware into neural networks
Open3d learning note 4 [surface reconstruction]
Introduction to parameters of CarSim pavement 3D shape file
It's great to save 10000 pictures of girls
CVPR19-Deep Stacked Hierarchical Multi-patch Network for Image Deblurring论文复现
Array and string processing, common status codes, differences between PHP and JS (JS)
Carsim-問題Failed to start Solver: PATH_ID_OBJ(X) was set to Y; no corresponding value of XXXXX?
OpenCV 6.4 中值滤波器的使用
图像增强的几个方法以及Matlab代码
随机推荐
使用C#语言来进行json串的接收
High school mathematics compulsory one
Deep understanding of JVM
Carla-UE4Editor导入RoadRunner地图文件(保姆级教程)
用于类别增量学习的动态可扩展表征 -- DER
Jupyter Notebook常用快捷键(在命令模式中按H也可查看)
Meta Learning 简述
力扣方法总结:滑动窗口
稀疏矩阵存储
Global and Chinese markets for conventional rubber track 2022-2028: Research Report on technology, participants, trends, market size and share
Summary of one question per day: String article (continuously updated)
Matlab数学建模工具
Use of OpenCV 6.4 median filter
Force buckle method summary: sliding window
Sequence problem for tqdm and print
11月24号,我们为“满月”庆祝
Go functions make, slice, append
OpenCV3 6.3 用滤波器进行缩减像素采样
Carsim 学习心得-粗略翻译1
Summary of one question per day: stack and queue (continuously updated)