There are many ways to reverse-build Pojo and Mapper files using MyBatis, which I used to generate from Mybtais's own generator package, connected as follows: MyBatis build Pojo yourself
Today I used the idea to build Pojo and mapper using the MAVEN project, as follows:
1, first configure the Pom.xml file, first configure the plug-in plugin
The configuration file is as follows
<Build> <Plugins> <!--MyBatis Reverse Engineering - <plugin> <groupId>Org.mybatis.generator</groupId> <Artifactid>Mybatis-generator-maven-plugin</Artifactid> <version>1.3.2</version> <Configuration> <!--location of the configuration file - <ConfigurationFile>Src/main/resources/personal-generatorconfig.xml</ConfigurationFile> <verbose>True</verbose> <Overwrite>True</Overwrite> </Configuration> </plugin> </Plugins> </Build>
2, add the configuration file to the project as shown above in the profile directory location, add the Personal-generatorconfig.xml file, and then add the configuration file personal-db.properties, location structure:
Where the code for Personal-generator.xml is as follows
<?XML version= "1.0" encoding= "UTF-8"?><!DOCTYPE generatorconfiguration Public "-//mybatis.org//dtd mybatis Generator Configuration 1.0//en" "Htt P://mybatis.org/dtd/mybatis-generator-config_1_0.dtd "><generatorconfiguration> <PropertiesResource= "Personal-db.properties"></Properties> <Classpathentry Location= "${jdbc.driverlocation}" /> <!--classpathentry location= "D:\zngkpt\m2\repository\mysql\mysql-connector-java\5.1.40\ Mysql-connector-java-5.1.40.jar "/ - <ContextID= "Context1"Targetruntime= "MyBatis3"> <Commentgenerator> <!--Remove Auto-generated annotations - < Propertyname= "Suppressallcomments"value= "true" /> </Commentgenerator> <!--Database Connection Configuration - <jdbcconnectionDriverclass= "${jdbc.driverclass}"Connectionurl= "${jdbc.connectionurl}"userId= "${jdbc.userid}"Password= "${jdbc.password}" /> <!--jdbcconnection driverclass= "Com.mysql.jdbc.Driver" connectionurl= "jdbc:mysql://localhost:3306/t Est "userid=" root "password=" MySQL "/ - <!--non-mandatory, type-processor, conversion control between database type and Java type - <Javatyperesolver> < Propertyname= "Forcebigdecimals"value= "false"/> </Javatyperesolver> <!--Configure generated entity package Targetpackage: Generated entity package location, default in src directory targetproject: Target project name - <JavamodelgeneratorTargetpackage= "Com.unisits.zngkpt.common.userprivrman.pojo"Targetproject= "Src/main/java" /> <!--The location and name of the mapping file for the entity package, which is stored in the SRC directory by default - <SqlmapgeneratorTargetpackage= "Com.unisits.zngkpt.common.userprivrman.mapper"Targetproject= "Src/main/java" /> <!--Configuration Table Schema: Do not fill in tableName: Table name Enablecountbyexample, Enableselectbyexample, Enabledele Tebyexample, Enableupdatebyexample, Selectbyexamplequeryid: Examples of automatic generation removal - <TableSchema=""TableName= "Sys_role"Enablecountbyexample= "false"Enableselectbyexample= "false"Enabledeletebyexample= "false"Enableupdatebyexample= "false"Selectbyexamplequeryid= "false" > </Table> <TableSchema=""TableName= "Sys_permission"Enablecountbyexample= "false"Enableselectbyexample= "false"Enabledeletebyexample= "false"Enableupdatebyexample= "false"Selectbyexamplequeryid= "false" > </Table> <TableSchema=""TableName= "Sys_role_permission"Enablecountbyexample= "false"Enableselectbyexample= "false"Enabledeletebyexample= "false"Enableupdatebyexample= "false"Selectbyexamplequeryid= "false" > </Table> <TableSchema=""TableName= "Sys_user"Enablecountbyexample= "false"Enableselectbyexample= "false"Enabledeletebyexample= "false"Enableupdatebyexample= "false"Selectbyexamplequeryid= "false" > </Table> <TableSchema=""TableName= "Sys_user_role"Enablecountbyexample= "false"Enableselectbyexample= "false"Enabledeletebyexample= "false"Enableupdatebyexample= "false"Selectbyexamplequeryid= "false" > </Table> <TableSchema=""TableName= "Unit_info"Enablecountbyexample= "false"Enableselectbyexample= "false"Enabledeletebyexample= "false"Enableupdatebyexample= "false"Selectbyexamplequeryid= "false" > </Table> <TableSchema=""TableName= "Unit_type"Enablecountbyexample= "false"Enableselectbyexample= "false"Enabledeletebyexample= "false"Enableupdatebyexample= "false"Selectbyexamplequeryid= "false" > </Table> </Context></generatorconfiguration>
The code for Personal-db.properties is as follows
jdbc.driverlocation=d:\\zngkpt\\m2\\repository\\com\\microsoft\\sqlserver\\sqljdbc4\\4.0\\ Sqljdbc4-4.0.jarjdbc.driverclass=com.microsoft.sqlserver.jdbc.sqlserverdriverjdbc.connectionurl=jdbc:sqlserver ://127.0.0.1:1434;databasename=db_zngkptjdbc.userid=sajdbc.password=123456
3, so far, all the MyBatis configuration work is over, start configuring idea to run the build Pojo.
Click the menu Run->edit Configuration, then in the top left corner of the popup form, click +->maven, the form below appears
Then click Apply, OK, then run the maven that you just created, and the resulting structure is as follows
MyBatis using generator reverse engineering to generate pojo,mapper in idea