http://www.mybatis.org/generator/index.html
方法一:eclipse插件式
1.下载 mybatis-generator-core-1.3.2.jar
解压后添加到eclipse插件
2.创建mybatis Generator配置文件
File→Other→Mybatis Generator Configuration File→选择路径→成功生成配置文件
3.配置配置文件
<?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 > <!-- jar绝对路径 --> <classPathEntry location="D:zlinstantclient_11_264ojdbc6.jar"/> <context id="context1" > <jdbcConnection driverClass="oracle.jdbc.driver.OracleDriver" connectionURL="jdbc:oracle:thin:@192.168.1.8:1521:rhhis" userId="tjglxt" password="tjglxt" /> <!-- 实体类生成后所在包和项目位置 --> <javaModelGenerator targetPackage="cn.mode" targetProject="ssmAnnotation" /> <!-- 映射文件生成后所在包和项目位置 --> <sqlMapGenerator targetPackage="cn.map" targetProject="ssmAnnotation" /> <!-- Dao生成后所在包和项目位置 --> <javaClientGenerator targetPackage="cn.client" targetProject="ssmAnnotation" type="XMLMAPPER" /> <table tableName="ssmtest" > <columnOverride column="id" property="id" /> <columnOverride column="name" property="name" /> <columnOverride column="age" property="age" /> </table> </context> </generatorConfiguration>
4.生成代码
在generator配置文件上右键→Generate MyBatis/IBATIS Artifacts→成功生成