MyBatis is a semi-automatic ORM framework, so the main task is to configure Mapping mapping files. But because handwritten mapping files are easy to make mistakes, MyBatis generators can be used to automatically generate entity classes, DAO interfaces and Mapping mapping files. This saves a lot of effort, copy ing the generated code into the project.
There are many ways to install plug-ins in eclipse using auto-generation, but the way I'm going to introduce below is very easy and simple. It doesn't need to install plug-ins, just a few jar packages and put them under a directory.
The files and jar packages needed to generate the code:
(Download address of the above file: http://download.csdn.net/detail/u012909091/7206091)
There are jar packages for the mybatis framework. data base Driver jar package and MyBatis generator jar package. GeneorConfig. XML is the file that we need to configure. The configuration is 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>
-
-
<classPathEntry location="mysql-connector-java-5.1.25-bin.jar"/>
-
<context id="DB2Tables" targetRuntime="MyBatis3">
-
<commentGenerator>
-
<property name="suppressDate" value="true"/>
-
-
<property name="suppressAllComments" value="true"/>
-
</commentGenerator>
-
-
<jdbcConnection driverClass="com.mysql.jdbc.Driver" connectionURL="jdbc:mysql://125.221.1.1/db_124" userId="dem" password="dem">
-
</jdbcConnection>
-
<javaTypeResolver>
-
<property name="forceBigDecimals" value="false"/>
-
</javaTypeResolver>
-
-
<javaModelGenerator targetPackage="test.domain" targetProject="src">
-
<property name="enableSubPackages" value="true"/>
-
<property name="trimStrings" value="true"/>
-
</javaModelGenerator>
-
-
<sqlMapGenerator targetPackage="test.mapping" targetProject="src">
-
<property name="enableSubPackages" value="true"/>
-
</sqlMapGenerator>
-
-
<javaClientGenerator type="XMLMAPPER" targetPackage="test.IDao" targetProject="src">
-
<property name="enableSubPackages" value="true"/>
-
</javaClientGenerator>
-
-
<table tableName="user_info_t" domainObjectName="User" enableCountByExample="false" enableUpdateByExample="false" enableDeleteByExample="false" enableSelectByExample="false" selectByExampleQueryId="false"></table>
-
</context>
-
</generatorConfiguration>
When all this is done, just open the console, enter the lib directory, and execute the script:
Java -jar mybatis-generator-core-1.3.2.jar -configfile generatorConfig.xml -overwrite
That's all.
After generation, you can find the corresponding folder in the src directory, and each table corresponds to three files (entity class, interface, configuration file).