1. Introduction to MyBatisX Generator
MyBatisX Generator is a code generator for generating MyBatis code. It can automatically generate entity classes, mapping files and Mapper interfaces according to the database table structure.
Using MyBatisX Generator can simplify the development process, without manually writing a lot of repetitive code, and improve development efficiency.
When I have a lot of database table fields, I don’t want to write the mapped entity classes and mappers by hand, so I can use the MyBatisX Generator tool
2. Use steps
2.1 Establish a database connection
1. Idea plugin management, download the plugin MyBatisX Generator
2. On the right side of the idea, click Database to create a new MySQL connection
Database->➕->Data Source->Mysql
3. After the new creation is completed, click the circle to refresh it, and you can see the corresponding table under this database
2.2 Automatically generate entity classes, mapping files and Mapper interfaces
1. Right-click the table that you need to generate code to display the MyBatisX-Generator plug-in
2. Click the MyBatisX-Generator plug-in to configure the generated code
3. The only thing that needs to be changed is the relative package item. Fill in which package the entity class needs to be placed in
4. Click Next
5. Configuration template
I need to tick the following options:
1. Comment automatically generates comments
2、Lombok
The template I choose is default -all, which will help me generate Xml files and interfaces.
You can use different templates according to your needs
Notice:
The package name of mapperXml and mapperInterface must be consistent.
For example, my default display here is
mapperInterface com.example.xx.mapper
mapperXml mapper
I need to manually change their paths to be consistent
all for
mapperInterface com.example.xx.mapper
mapperXml com.example.xx.mapper
Then click Finish and you're done