mybatis也能方向生成代码,能方向生成实体类(pojo)、mapper接口和Mapper接口映射文件,能减少我们代码的工作量。详细步骤如下
1、https://github.com/mybatis/generator/releases下载org.mybatis.generator.eclipse.site-1.3.5.201609070108.zip,解压架包把features、plugins文件夹下的架包分别拷贝到eclipse安装目录下的features、plugins文件夹。重启eclipse就行。
解压后图片如下:
Eclipse路径如图:
拷贝替换如图:
2、创建generatorConfig.xml文件,安装好mybatis 就能创建generatorConfig.xml
3、配置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:\rep\mysql\mysql-connector-java\5.1.19\mysql-connector-java-5.1.19.jar" /> -->
- <classPathEntry location="D:\repo\com\oracle\ojdbc14\10.2.0.1.0\ojdbc14-10.2.0.1.0.jar" />
- <context id="DB2Tables" targetRuntime="MyBatis3">
- <commentGenerator>
- <property name="suppressAllComments" value="true" />
- <property name="suppressDate" value="true" />
- </commentGenerator>
- <jdbcConnection driverClass="oracle.jdbc.driver.OracleDriver" connectionURL="jdbc:oracle:thin:@xxx.xxx.xxx.xxx:1521:orcl4" userId="xxx" password="xxxx" />
- <javaTypeResolver>
- <property name="forceBigDecimals" value="false" />
- <!-- 默认false,把JDBC DECIMAL 和 NUMERIC 类型解析为 Integer true,把JDBC DECIMAL 和 NUMERIC 类型解析为java.math.BigDecimal -->
- </javaTypeResolver>
- <javaModelGenerator targetPackage="com.pcmall.domain.sale.order" targetProject="pos-service/src/main/java">
- <property name="enableSubPackages" value="true" />
- <property name="trimStrings" value="true" />
- </javaModelGenerator>
- <sqlMapGenerator targetPackage="mybatis.mapper.sale.order" targetProject="pos-service/src/main/resources">
- <property name="enableSubPackages" value="false" />
- </sqlMapGenerator>
- <javaClientGenerator targetPackage="com.pcmall.dao.sale.order" targetProject="pos-service/src/main/java" type="XMLMAPPER">
- <property name="enableSubPackages" value="false" />
- </javaClientGenerator>
- <table tableName="hs_zxzflx" enableSelectByExample="false" enableDeleteByExample="false" enableCountByExample="false" selectByExampleQueryId="true" enableUpdateByExample="false">
- <!-- <generatedKey column="ID" sqlStatement="oracle" identity="true" /> -->
- </table>
- </context>
- </generatorConfiguration>