MyBatis代码生成工具mybatis-generator在Myeclipse2014中的使用
一、在MyEclipse安装目录下新建MyPlugin目录,如下图所示:
二、将 mybatis.zip 里面的文件放在MyEclipse的dropins目录下,如下图所示:
三、在Myeclipse安装目录dropins下,新建mybatis.link文件,并在文件中指明mybatis-generator放置的路径:
四、将Mybatis需要的 mysql-connector-java-5.1.23.jar 等jar包引入项目;
五、在项目中放入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> <properties resource="generatorConfig.properties" /> <context id="context1" targetRuntime="MyBatis3" defaultModelType="flat"> <plugin type="org.mybatis.generator.plugins.RowBoundsPlugin"></plugin> <plugin type="org.mybatis.generator.plugins.SerializablePlugin"></plugin> <commentGenerator> <!-- 是否去除自动生成的注释 true:是 : false:否 --> <property name="suppressAllComments" value="true" /> </commentGenerator> <jdbcConnection driverClass="${driverClass}" connectionURL="${connectionURL}" userId="${user}" password="${password}" /> <!-- 默认false,把JDBC DECIMAL 和 NUMERIC 类型解析为 Integer true,把JDBC DECIMAL 和 NUMERIC 类型解析为java.math.BigDecimal --> <javaTypeResolver> <property name="forceBigDecimals" value="false" /> </javaTypeResolver> <javaModelGenerator targetPackage="${modelPackage}" targetProject="a-base\src\main\java"> <property name="trimStrings" value="true" /> </javaModelGenerator> <sqlMapGenerator targetPackage="${sqlMapperPackage}" targetProject="a-base\src\main\java" /> <javaClientGenerator targetPackage="${daoMapperPackage}" targetProject="a-base\src\main\java" type="XMLMAPPER" /> <table tableName="account_phone" domainObjectName="AccountPhone" ></table> <!--<table tableName="app_version" domainObjectName="AppVersion" ><columnOverride column="content" jdbcType="VARCHAR"/> </table> <table tableName="deposit" domainObjectName="Deposit" ><columnOverride column="bank_ret" jdbcType="VARCHAR"/> </table> --> <!--<table tableName="order_id_gen" domainObjectName="OrderIdGen" ></table> --> <!--<table tableName="withdraw" domainObjectName="Withdraw"></table>--> <!-- <table tableName="user_bank" domainObjectName="UserBank" ></table> --> <!--<table tableName="cash_log" domainObjectName="CashLog" ></table> --> <!-- <table tableName="project" domainObjectName="Project" ></table> --> <!-- <table tableName="project_daily" domainObjectName="ProjectDaily" ></table> <table tableName="project_manhour" domainObjectName="ProjectManhour" ></table> --> <!--<table tableName="project_member" domainObjectName="ProjectMember"></table> --> <!--<table tableName="sys_resource" domainObjectName="SysResource" ></table> <table tableName="sys_role" domainObjectName="SysRole" ></table> <table tableName="sys_user" domainObjectName="SysUser" ></table> --> <!-- <table tableName="transfer_item" domainObjectName="TransferItem" ></table> --> <!--<table tableName="transfer_order" domainObjectName="TransferOrder" ></table> --> <!--<table tableName="apply_user" domainObjectName="ApplyUser" ></table> --> <!--<table tableName="user" domainObjectName="User" ></table> --> <!--<table tableName="account" domainObjectName="Account" ></table> --> <!--<table tableName="user_login_log" domainObjectName="UserLoginLog" ></table> <table tableName="user_log" domainObjectName="UserLog" ></table> --> <!--<table tableName="api" ></table> <table tableName="api_module"></table> --> <!--<table tableName="api_param"></table> <table tableName="api_retparam"></table> --> </context> </generatorConfiguration>
generatorConfig.properties文件
driverClass=com.mysql.jdbc.Driver connectionURL=jdbc:mysql://localhost:3306/test?useUnicode=true&characterEncoding=UTF8 user=root password=123456 modelPackage=brant.base.domain sqlMapperPackage=brant.base.persistence daoMapperPackage=brant.base.persistence
六、重启Myeclipse,鼠标右击generatorConfig.xml 文件,在弹出的菜单中选择Generate MyBatis/iBATIS Artifacts 即可生成所需文件:
------------------------------
Brant Liu
lbf1988@qq.com
有梦想的码农
Brant Liu
lbf1988@qq.com
有梦想的码农