Mybatis-generator Code generation Tool (Maven method)
MyBatis Generator Detailed
IntelliJ Idea 14 uses Mybatis-generator to automatically generate MyBatis code
Develop MyBatis reverse engineering with idea
Pom.xml file Configuration
<dependencies>
<dependency>
<groupId>mysql</groupId>
<artifactId> mysql-connector-java</artifactid>
<version>5.1.35</version>
</dependency>
<dependency>
<groupId>org.mybatis.generator</groupId>
<artifactId> mybatis-generator-core</artifactid>
<version>1.3.2</version>
</dependency>
</dependencies>
<plugin>
<groupId>org.mybatis.generator</groupId>
<artifactId>mybatis-generator-maven-plugin</artifactId>
<version>1.3.2</ Version>
</plugin>
Generatorconfig.xml
<?xml version= "1.0" encoding= "UTF-8"?> <! DOCTYPE generatorconfiguration Public "-//mybatis.org//dtd mybatis generator Configuration" "1.0//en G/dtd/mybatis-generator-config_1_0.dtd "> <generatorConfiguration> <context id=" Testtables "
Targetruntime= "MyBatis3" > <commentGenerator> <!--whether to remove automatically generated comments true: false: No--> <property name= "Suppressallcomments" value= "true"/> </commentGenerator> <!--database connection Info: Driver class, connection address, username, password--> <jdbcconnection driverclass= "Com.mysql.jdbc.Driver connectionurl=" jdbc:m Ysql://localhost:3306/mybatis "userid=" root "password=" xiaxunwu1996.
> </jdbcConnection> <!--<jdbcconnection driverclass= "Oracle.jdbc.OracleDriver" Connectionurl= "JDBC:ORACLE:THIN:@127.0.0.1:1521:YYCG" userid= "YYCG" password= "YYCG" > & Lt;/jdbcconnection>-->
<!--default false to resolve JDBC decimal and NUMERIC types to integers, and to resolve JDBC decimal and NUMERIC types to Java.math when True.
BigDecimal--> <javaTypeResolver> <property name= "Forcebigdecimals" value= "false"/> </javaTypeResolver> <!--targetproject: position to generate PO class--> <javamodelgenerator Targetpackag E= "Po" targetproject= ". \src" > <!--enablesubpackages: whether to have schema as the suffix of the package--> < The property name= "Enablesubpackages" value= "false"/> <!--the space before and after the value returned from the database is cleared--> Name= "Trimstrings" value= "true"/> </javaModelGenerator> <!--targetproject:mapper Map file generation location- -> <sqlmapgenerator targetpackage= "mapper" targetproject= "\SRC" > <!--Enables Ubpackages: Let schema be the suffix of the package--> <property name= "Enablesubpackages" value= "false"/> Pgenerator> <!
--Targetpackage:mapper interface generated location--> <javaclientgenerator type= "Xmlmapper" targetpackage= "Mapper" Targetproject= ". \src" > <!--enablesubpackages: Let schema be the suffix of the package--> <propert
Y name= "Enablesubpackages" value= "false"/> </javaClientGenerator> <!--Specify database table--> <table tablename= "Items" ></table> <table tablename= "Orders" ></table> <table tab
Lename= "OrderDetail" ></table> <!--<table schema= "tablename=" Sys_user "></table> <table schema= "" Tablename= "Sys_role" ></table> <table schema= "" Tablename= "Sys_permission" ></ table> <table schema= "tablename=" Sys_user_role "></table> <table schema=" "Tablename=" s Ys_role_permission "></table>--> <!--some table fields need to specify the Java type <table schema=" Tablename= "" &G
T <cOlumnoverride column= "" javatype= ""/> </table>--> </context> </GENERATORCONFIGURATION&G T
Where to modify:
Javamodelgenerator, generate the position of the PO class
Location of Sqlmapgenerator,mapper Map file generation
Where the Javaclientgenerator,mapper interface is built
Table, whose TableName property corresponds to the corresponding tables in the database
Create a new Generator.java file under the SRC package
Import Java.io.File;
Import java.util.ArrayList;
Import java.util.List;
Import Org.mybatis.generator.api.MyBatisGenerator;
Import org.mybatis.generator.config.Configuration;
Import Org.mybatis.generator.config.xml.ConfigurationParser;
Import Org.mybatis.generator.internal.DefaultShellCallback; public class Generatorsqlmap {public void Generator () throws exception{list<string> warnings = new A
Rraylist<string> ();
Boolean overwrite = true;
Specifies the reverse engineering profile file ConfigFile = new file ("Src/generatorconfig.xml");
Configurationparser cp = new Configurationparser (warnings);
Configuration config = cp.parseconfiguration (configfile);
Defaultshellcallback callback = new Defaultshellcallback (overwrite);
Mybatisgenerator mybatisgenerator = new Mybatisgenerator (config, callback, warnings);
Mybatisgenerator.generate (NULL);
public static void Main (string[] args) throws Exception { try {generatorsqlmap generatorsqlmap = new Generatorsqlmap ();
Generatorsqlmap.generator ();
catch (Exception e) {e.printstacktrace (); }
}
}
2018. 2. 28 Update
You can create a new project to generate this PO, DAO, Mapper
The specific methods are as follows:
IntelliJ Idea 14 uses Mybatis-generator to automatically generate MyBatis code
http://blog.csdn.net/sunny243788557/article/details/45166397