In the context of the MBG targetRuntime configured as MyBatis 3 , Example MBG is generated and related objects and methods , to introduce this section relating to Example methods .
Create a new table for the country related to Example MBG profiles , new profiles generatorConfig-country.xml follows .
<?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="C:\Users\kangy\.m2\repository\mysql\mysql-connector-java\5.1.45\mysql-connector-java-5.1.45.jar"/> <context id="MySqlContext" targetRuntime="MyBatis3" defaultModelType="flat"> <property name="javaFileEncoding" value="UTF-8"/> <commentGenerator> <property name="suppressDate" value="true"/> <property name="addRemarkComments" value="true"/> </commentGenerator> <jdbcConnection driverClass="com.mysql.jdbc.Driver" connectionURL="jdbc:mysql://localhost:3306/testmybatis" userId="root" password="root"> </jdbcConnection> <javaModelGenerator targetPackage="tk.mybatis.simple.model" targetProject="simple\src\main\java"> <property name="trimStrings" value="true" /> </javaModelGenerator> <sqlMapGenerator targetPackage="tk.mybatis.simple.mapper" targetProject="simple\src\main\resources"/> <javaClientGenerator type="XMLMAPPER" targetPackage="tk.mybatis.simple.mapper" targetProject="simple\src\main\java"/> <table tableName="country"> <generatedKey column="id" sqlStatement="MySql"/> </table> </context> </generatorConfiguration>
This configuration is carried out for the Eclipse plug-in , so if you use other means , please pay attention to modify targetProject property .
The above configuration of the package name is in accordance with Chapter 2 of specification writing , and therefore the original conflict Country object (XML Mapper interfaces and because the use of Eclipse plug-ins , so there is no conflict ) . In this case , Mr. into the code , and then deal with inconsistencies .
After generating the code can be found CountryMapper interface adds a number of basic methods , CountryMapper.xml also increased corresponding SQL statement .
Here in the original by adding a new test CountryMapperTest test to understand the relevant class of usage Example . First Example object by means of a comprehensive call to understand Example , the following code .