mybatis代码生成

自动生成 mybatis代码,特别是sqlmap文件,可以有效的减少dao等代码的重复劳动。
eclipse中添加插件: mybatis Generator - http://mybatis.googlecode.com/svn/sub-projects/generator/trunk/eclipse/UpdateSite/


添加生成代码的配置文件



<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE ibatorConfiguration PUBLIC "-//Apache Software Foundation//DTD Apache iBATIS Ibator Configuration 1.0//EN" "http://ibatis.apache.org/dtd/ibator-config_1_0.dtd" >

<ibatorConfiguration>
<classPathEntry
location="/home/xxx/xxx.war/WEB-INF/lib/mysql-connector-java-5.1.6.jar" />

<ibatorContext id="DB2Tables" targetRuntime="Ibatis2Java5">

<!-- 去除自动生成的注释 -->
<commentGenerator>
<property name="suppressAllComments" value="true" />
<!-- 是否生成注释代时间戳
<property name="suppressDate" value="true" />
-->
</commentGenerator>

<jdbcConnection driverClass="com.mysql.jdbc.Driver"
connectionURL="jdbc:mysql://localhost/test" userId="test"
password="123456">
</jdbcConnection>

<javaTypeResolver>
<property name="forceBigDecimals" value="false" />
</javaTypeResolver>

<javaModelGenerator targetPackage="test.model"
targetProject="Test-web">
<property name="enableSubPackages" value="true" />
<property name="trimStrings" value="true" />
</javaModelGenerator>

<sqlMapGenerator targetPackage="test.dao"
targetProject="Test-web">
<property name="enableSubPackages" value="true" />
</sqlMapGenerator>

<!-- 生成DAO的类文件以及配置文件 -->
<daoGenerator targetPackage="test.dao" targetProject="Test-web"
type="GENERIC-CI" />

<!-- 避免生成一大堆Example方法,代码看去清晰一些 -->
<table tableName="user" domainObjectName="User"
enableCountByExample="false" enableUpdateByExample="false"
enableDeleteByExample="false" enableSelectByExample="false"
selectByExampleQueryId="false">

<!-- 去除一列,这样 PASSWORD这列就不会生成
<ignoreColumn column="PASSWORD"/>
-->
<!-- columnOverride 将数据库字段对应成javabean里面的字段 -->
<columnOverride column="USERID" property="userid" />
<columnOverride column="USERNAME" property="username" />
<columnOverride column="PASSWORD" property="password" />
</table>

</ibatorContext>
</ibatorConfiguration>



在文件上点击鼠标右键,可以看到插件生成的选项,选择即可生成代码

daoGenerator 标签的类型,见如下链接.
http://ibatis.apache.org/docs/tools/abator/configreference/daoGenerator.html

IBATIS The generated DAO objects will conform to the iBATIS DAO framework.
GENERIC-CI The generated DAO objects will rely only on the SqlMapClient. The SqlMapClient will be supplied by constructor dependency injection.
GENERIC-SI The generated DAO objects will rely only on the SqlMapClient. The SqlMapClient will be supplied by setter dependency injection.
SPRING The generated DAO objects will conform to the Spring DAO framework.
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值