当前位置:网站首页>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
freemarkerrely on , This is because the version is too low , Upgrade to2.3.30that 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=truethat 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 !
边栏推荐
- Programmers can only be 35? The 74 year old programmer in the United States has been programming for 57 years and has not retired
- It's great to save 10000 pictures of girls
- Carsim problem failed to start Solver: Path Id Obj (X) was set to y; Aucune valeur de correction de xxxxx?
- Go functions make, slice, append
- Command line is too long
- How to back up the configuration before the idea when reinstalling the idea
- The internal network of the server can be accessed, but the external network cannot be accessed
- How to wrap qstring strings
- Learn to write article format
- Opencv common method source link (continuous update)
猜你喜欢

Replace convolution with full connection layer -- repmlp

Look for we media materials from four aspects to ensure your creative inspiration

Static library and dynamic library

Use of opencv3 6.2 low pass filter

VS Code配置问题

乐理基础(简述)

OpenCV3 6.3 用滤波器进行缩减像素采样

Replace self attention with MLP

Command line is too long

Dynamic extensible representation for category incremental learning -- der
随机推荐
St-link connection error invalid ROM table of STM32 difficult and miscellaneous diseases
OpenCV关于x,y坐标容易混淆的心得
High school mathematics compulsory one
Cvpr19 deep stacked hierarchical multi patch network for image deblurring paper reproduction
Meta learning Brief
Prompt 范式简述
我的vim配置文件
用于类别增量学习的动态可扩展表征 -- DER
Principes fondamentaux de la théorie musicale (brève introduction)
[learning notes] matlab self compiled image convolution function
Carla-ue4editor import Roadrunner map file (nanny level tutorial)
Wang extracurricular words
Eklavya -- infer the parameters of functions in binary files using neural network
Opencv3 6.3 reduced pixel sampling with filters
Programmers can only be 35? The 74 year old programmer in the United States has been programming for 57 years and has not retired
Business architecture diagram
Carsim problem failed to start Solver: Path Id Obj (X) was set to y; Aucune valeur de correction de xxxxx?
Carsim-路面3D形状文件参数介绍
Force buckle method summary: sliding window
Constant pointer and pointer constant