Install and use the MyBatis_Generator plugin.
MyBatis_Generator_1.3.1.zip
1. Download the installation package
Installation Package name: MyBatis_Generator_1.3.1.zip
2. install on Eclipse
LAdd plug-insIn the compressed packageFeaturesAnd plugins are copied to the features and plugins folders of eclipse.
LRestartEclipseTo verify whether the installation is successful.
The installation is successful!
3 User Guide
After creating a Maven project, follow these steps:
1.CreateGeneratorConfigFile
2. generatorConfig. xmlFile Configuration
JdbcConnection --- Database link URL, user name, and password
JavaModelGenerator--- Generate the package name and location of the model, which is the storage path configuration of some entity classes used in mybatis.
SqlMapGenerator--- The registration and location of the generated ing file are the storage path configuration of the xml file corresponding to the SQL statement written by mybatis.
JavaClientGenerator--- Generate the package name and location of DAO, which is the storage path of dao interface in mybatis
Table--- This configuration item is the database table configured for operation in the project.
(1) Pom. xmlAdd dependency
(2) Run the project and run-Maven install
After successful execution, the dependent packages will be downloaded from the repository. (If so, keep skip and build success)
(3) Find mysqlJarPackage location
The location of the jar package will be used in the configuration file generatorConfig. xml.
E: \ RepMaven \ mysql-connector-java \ 5.1.38 \ mysql-connector-java-5.1.38.jar
<ClassPathEntry location ="E: \ RepMaven \ mysql-connector-java \ 5.1.38 \ mysql-connector-java-5.1.38.jar"/>
(4) View the database information of the table.
<JdbcConnection
DriverClass ="Com. mysql. jdbc. Driver"
ConnectionURL ="Jdbc: mysql: // localhost: 3306/test"UserId ="Root"
Password ="Root"/>
<Table tableName ="Users"DomainObjectName ="UserInfo"/>
TableName: database table used to automatically generate code
DomainObjectName: name of the an class corresponding to the database table
(5) After configuration, run mybatisConfig. xml.
Right-click mybatisConfig. xml and choose generate mybatis ....
(7) View the results and automatically create the code structure:
(8) View detailed code
4. Notes
L generatorConfig. xml must be correctly configured. If an error occurs in the created table name, the following error may occur:
Incorrect Configuration:
Correct Configuration:
L The targetProject PATH uses relative paths. Do not use absolute paths. Otherwise, an error is returned:
Incorrect Configuration:
Error message:
Correct Configuration: