Foreword: In daily development, it is often necessary to repeatedly write some basic additions, deletions, changes, and query interfaces. Although it is not difficult, it will take us some time, so I developed a set of code generators implemented purely by SpringBoot, which can provide us with Generate addition, deletion, modification and query of a single piece of data, and can also generate batch addition, modification and deletion of multiple pieces of data, which can greatly improve our development efficiency. In this blog, I will introduce the usage tutorial of this set of code generators in detail.
Originality is not easy, every line of code is purely handwritten by the blogger, free and open source for everyone, I hope you can like, follow and bookmark to support!
The latest version: Tuantuan Code Generator V2.0: One-click generation of complete CRUD functions (heavy attack!)
Table of contents
2.1. Modify the yml configuration file
4. Actual development and testing
4.5, ServiceImpl.java implementation class
1. Project introduction
The code generator developed this time is implemented purely in SpringBoot. The whole project is very simple and easy to use. The blogger took about a week to write it. Currently, the code generator only supports the MySQL version .
Note: If you need MySQL to support batch operations, you need to add allowMultiQueries=true in the url configuration of yml, and support batch execution of SQL separated by ;.
For example:
spring:
datasource:
url: jdbc:mysql://localhost:3306/test?allowMultiQueries=true&useSSL=false
username:
password:
Technology selection:
1、SpringBoot2.7
2. MyBatis Persistence Layer Framework
3. Velocity template engine
4. MySQL database
...
Operating environment:
1、Maven3.8.1
2、JDK1.8
Currently supports one-click generation of the following files:
1. Domain.java entity class
2. Mapper.xml file
3. Mapper.java interface
4. Service.java interface
5. ServiceImpl.java implementation class
The controller layer is not generated on my side, because everyone's packaged result set is different, so it needs to be written by hand.
Two, Gitee source code
Code Cloud Address: Tuantuan Code Generator V1.0: Generate complete CRUD functions with one click
3. Project tutorial
In fact, there are only 2 steps to generate the code, configure the information, and run it.
2.1. Modify the yml configuration file
When you pull down the project, you need to configure the following information in yml:
1. Your database information.
2. The name of the table to be generated.
3. The storage path of the generated code file.
Note: The path must be in English, if there is no folder, the program will automatically create a new one.
2.2. Running unit tests
My database name is generate, and a new user table is created in it.
This is a table property.
Then find the TableColumnApplicationTests unit test file, and run it directly to generate it with one click!
Locate the generated files against your local disk.
That's it! Isn't it super simple O(∩_∩)O.
4. Actual development and testing
I directly omitted the process of building SpringBoot, and quickly demonstrated to you how to use the generated code in actual project development.
Simply configure the MySQL link and Mybatis configuration, and create new domain, service, serviceImpl, mapper and mapping packages.
4.1, Entity class
Paste in the generated User entity class.
4.2, Mapper.java interface
Paste in the generated UserMapper interface.
4.3, Mapper.xml file
Paste the generated UserMapper.xml file.
4.4, Service.java interface
Paste in the generated UserService interface.
4.5, ServiceImpl.java implementation class
Paste in the generated UserServiceImpl implementation class.
4.6. Unit testing
The following unit test is carried out in the form of graphics and text, and each interface is tested.
4.6.1. Insert a piece of data
Database situation:
4.6.2. Modify a piece of data
Database situation:
4.6.3, query data
4.6.4. Delete a piece of data
Database situation:
4.6.5, batch insert data
Database situation:
4.6.6. Modify data in batches
Database situation:
4.6.7. Batch delete data
Database situation:
V. Summary
The above is all the complete functions of my code generator, isn't it very convenient! Free and open source for everyone, it can be used in many places, such as the school's graduation project, if you like it, please leave a comment for the blogger!