1. Create a maven project and modify pom.xml
<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 configuration file--> <configurationFile>src/main/resources/generatorConfig.xml</configurationFile> <verbose>true</verbose> <overwrite>true</overwrite> </configuration> </plugin> </plugins> </build>
2. Create a new Personal-DB.propertie (database connection file) under resources (you can also write to death)
jdbc.driverLocation=D:\\maven\\com\\oracle\\ojdbc14\\10.2.0.4.0\\ojdbc14-10.2.0.4.0.jar jdbc.driverClass=oracle.jdbc.driver.OracleDriver jdbc.connectionURL=jdbc:oracle:thin:@//localhost:1521/XE jdbc.userId=LOUIS jdbc.password=123456
3. Create a new generatorConfig.xml file under resources (the contents are as 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>
<properties resource="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" /-->
<context id="context1" targetRuntime="MyBatis3">
<commentGenerator>
<!-- Remove auto-generated comments-->
<property name="suppressAllComments" value="true" />
</commentGenerator>
<!-- Database connection configuration -->
<jdbcConnection driverClass="${jdbc.driverClass}"
connectionURL="${jdbc.connectionURL}"
userId="${jdbc.userId}"
password="${jdbc.password}" />
<!--jdbcConnection driverClass="com.mysql.jdbc.Driver"
connectionURL="jdbc:mysql://localhost:3306/test"
userId="root"
password="mysql" /-->
<!-- optional, type handler, conversion control between database types and java types -->
<javaTypeResolver>
<property name="forceBigDecimals" value="false"/>
</javaTypeResolver>
<!--Configure the generated entity package
targetPackage: The location of the generated entity package, which is stored in the src directory by default
targetProject: target project name
-->
<javaModelGenerator targetPackage="com.unisits.zngkpt.common.userprivrman.pojo"
targetProject="src/main/java" />
<!-- The location and name of the mapping file corresponding to the entity package, which is stored in the src directory by default -->
<sqlMapGenerator targetPackage="com.unisits.zngkpt.common.userprivrman.mapper" targetProject="src/main/java" />
<!-- mapper method layer, stored in the src directory by default -->
<javaClientGenerator type="XMLMAPPER" targetPackage="com.bldz.train.mapper" targetProject="src/main/java">
<property name="enableSubPackages" value="true"/>
</javaClientGenerator>
<!-- configuration table
schema: do not need to fill in
tableName: table name
enableCountByExample、enableSelectByExample、enableDeleteByExample、enableUpdateByExample、selectByExampleQueryId:
Remove auto-generated examples
-->
<table schema="" tableName="sys_role" enableCountByExample="false" enableSelectByExample="false"
enableDeleteByExample="false" enableUpdateByExample="false" selectByExampleQueryId="false" >
</table>
<table schema="" tableName="sys_permission" enableCountByExample="false" enableSelectByExample="false"
enableDeleteByExample="false" enableUpdateByExample="false" selectByExampleQueryId="false" >
</table>
<table schema="" tableName="sys_role_permission" enableCountByExample="false" enableSelectByExample="false"
enableDeleteByExample="false" enableUpdateByExample="false" selectByExampleQueryId="false" >
</table>
<table schema="" tableName="sys_user" enableCountByExample="false" enableSelectByExample="false"
enableDeleteByExample="false" enableUpdateByExample="false" selectByExampleQueryId="false" >
</table>
<table schema="" tableName="sys_user_role" enableCountByExample="false" enableSelectByExample="false"
enableDeleteByExample="false" enableUpdateByExample="false" selectByExampleQueryId="false" >
</table>
<table schema="" tableName="unit_info" enableCountByExample="false" enableSelectByExample="false"
enableDeleteByExample="false" enableUpdateByExample="false" selectByExampleQueryId="false" >
</table>
<table schema="" tableName="unit_type" enableCountByExample="false" enableSelectByExample="false"
enableDeleteByExample="false" enableUpdateByExample="false" selectByExampleQueryId="false" >
</table>
</context>
</generatorConfiguration>
3. Up to now, all the mybatis configuration work has ended, start to configure the idea to run and generate pojo
Click the menu Run->Edit Configuration, then in the upper left corner of the pop-up form, as follows, enter mybatis-generator:generate -e
then click OK
4. Run the maven edited just now, and it will be generated successfully without any accident
Supplement: The final red part will generate the mapper.java file corresponding to the method in xml
Reprinted:
http://www.cnblogs.com/ningheshutong/p/6376970.html