I. Introduction
Referred to the MBG, a specialized custom user MyBatis frame code generator, you can quickly generate the corresponding mapping file, interface, and according to Table bean class.
It supports basic CRUD, and QBC-style query conditions.
But the definition of these complex sql table joins, stored procedures, etc. we need to hand-code
• Official documents address http://www.mybatis.org/generator/
• The official address engineering https://github.com/mybatis/generator/releases
2.1, depending
<dependency> <groupId>org.mybatis.generator</groupId> <artifactId>mybatis-generator-core</artifactId> <version>1.3.2</version> </dependency>
2.2 add plug-ins: which also add a mysql connection driver dependent.
<!--mybatis-generator-maven-plugin--> <plugin> <groupId>org.mybatis.generator</groupId> <artifactId>mybatis-generator-maven-plugin</artifactId> <version>1.3.2</version> <configuration> <configurationFile>src/main/resources/generatorConfig.xml</configurationFile> <verbose>true</verbose> <overwrite>true</overwrite> </configuration> <dependencies> <dependency> <groupId>mysql</groupId> <artifactId>mysql-connector-java</artifactId> <version>5.1.32</version> </dependency> </dependencies> </plugin>
2.3 In the resources below to create a source folder generatorConfig.xml
<?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE generatorConfiguration PUBLIC "-//mybatis.org//DTD MyBatis Generator Configuration 1.0//EN" "http://mybatis.org/dtd/mybatis-generator-config_1_0.dtd"> <generatorConfiguration> <!-- <classPathEntry location="D:/Java/lib/mysql-connector-java-5.1.43.jar" />--> <context id="test" targetRuntime="MyBatis3"> <plugin type="org.mybatis.generator.plugins.EqualsHashCodePlugin"></plugin> <plugin type="org.mybatis.generator.plugins.SerializablePlugin"></plugin> <plugin type="org.mybatis.generator.plugins.ToStringPlugin "> </ plugin> false <commentGenerator> <-! date for removing this element annotation specifies whether to include the generated generated: Indicates Protection -> <- If the creation date, modification will cause even a field, all attributes of the class will change the entire entity, it is not conducive to version control, so set to true ->! <Property name = "suppressDate" value = "to true" /> ! <- whether to remove the auto-generated comments to true : is: false : No -> <Property name = "suppressAllComments" value = "to true" /> </ commentGenerator> <- database link! URL, user name, password -> <JdbcConnection driverClass = "com.mysql.jdbc.Driver" connectionURL = "jdbc: MySQL: // localhost: 3306 / crmpro" userId = "root" password="ych521mm"> <!-- </jdbcConnection> <javaTypeResolver> This property is used to specify whether MyBatis Generator should force the use of java.math.BigDecimal for DECIMAL and NUMERIC fields, --> <property name="forceBigDecimals" value="false" /> </javaTypeResolver> <!-- 指定javaBean的生成策略 文件夹自己定义--> <javaModelGenerator targetPackage="pojo" targetProject=".\src"> <property name="enableSubPackages" value="true" /> <property name="trimStrings" value="true" /> <- sqlMapGenerator:! mapped SQL generation strategy: -> </ javaModelGenerator> <sqlMapGenerator targetPackage = "DAO" targetProject=".\src"> <Property name = "enableSubPackages" = value "to true" /> </ sqlMapGenerator> <- javaClientGenerator:! mapper interface to specify the location where the -> <javaClientGenerator of the type = "XMLMAPPER" targetPackage = "DAO" targetProject =. "\ src"> <Property name = "enableSubPackages" = value "to true" /> </ javaClientGenerator> <- Specifies the reverse analysis which tables:! table to create javaBean -> <the table tableName = "account" domainObjectName = " Account"> </ table> <-! - to be generated which tables> <Table tableName = "Employee" domainObjectName = "the Employee" enableCountByExample="false" enableUpdateByExample="false" enableDeleteByExample="false" enableSelectByExample="false" selectByExampleQueryId="false"> </table> </context> </generatorConfiguration>
This generation is complete with code under maven environment idea! ! ! !