当前位置:网站首页>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 !
边栏推荐
- Static library and dynamic library
- E-R画图明确内容
- Open3d learning notes 1 [first glimpse, file reading]
- It's great to save 10000 pictures of girls
- Cvpr19 deep stacked hierarchical multi patch network for image deblurring paper reproduction
- 力扣每日一题刷题总结:栈与队列篇(持续更新)
- Jupyter Notebook常用快捷键(在命令模式中按H也可查看)
- Matlab-其它
- Summary of open3d environment errors
- Vscode下中文乱码问题
猜你喜欢

Several methods of image enhancement and matlab code

Target detection for long tail distribution -- balanced group softmax

服务器的内网可以访问,外网却不能访问的问题
![Open3d learning notes 1 [first glimpse, file reading]](/img/68/68ea87817dbf788591216a32c9375b.png)
Open3d learning notes 1 [first glimpse, file reading]

Principes fondamentaux de la théorie musicale (brève introduction)

St-link connection error invalid ROM table of STM32 difficult and miscellaneous diseases

Carla-UE4Editor导入RoadRunner地图文件(保姆级教程)

Income in the first month of naked resignation

On the confrontation samples and their generation methods in deep learning

The internal network of the server can be accessed, but the external network cannot be accessed
随机推荐
Global and Chinese market of recovery equipment 2022-2028: Research Report on technology, participants, trends, market size and share
St-link connection error invalid ROM table of STM32 difficult and miscellaneous diseases
Introduction to parameters of CarSim pavement 3D shape file
Library function of C language
乐理基础(简述)
JVM instructions
Global and Chinese market of tillage finishing machines 2022-2028: Research Report on technology, participants, trends, market size and share
In the era of short video, how to ensure that works are more popular?
Target detection for long tail distribution -- balanced group softmax
Jupyter Notebook常用快捷键(在命令模式中按H也可查看)
王-课外单词
Carsim problem failed to start Solver: Path Id Obj (X) was set to y; Aucune valeur de correction de xxxxx?
w10升级至W11系统,黑屏但鼠标与桌面快捷方式能用,如何解决
Sparse matrix storage
Matlab mathematical modeling tool
Simply test the two different data transmission methods of content length and chunked
SQL server如何卸载干净
Installation and use of simple packaging tools
业务架构图
利用Transformer来进行目标检测和语义分割