首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > JAVA > Eclipse开发 >

Abator代码生成工具 - -Eclipse上Ibatis|Mybatis代码生成工具 利器

2012-09-07 
Abator代码生成工具 - -Eclipse下Ibatis|Mybatis代码生成工具 利器?xml version1.0 encodingUTF-8?

Abator代码生成工具 - -Eclipse下Ibatis|Mybatis代码生成工具 利器
<?xml version="1.0" encoding="UTF-8"?><!DOCTYPE abatorConfiguration PUBLIC "-//Apache Software Foundation//DTD Abator for iBATIS Configuration 1.0//EN""http://ibatis.apache.org/dtd/abator-config_1_0.dtd"><abatorConfiguration><abatorContext generatorSet="???"> <!-- TODO: Add Database Connection Information --> <jdbcConnection driverClass="???" connectionURL="???" userId="???" password="???"> <classPathEntry location="???" /> </jdbcConnection> <javaModelGenerator targetPackage="???" targetProject="???" /> <sqlMapGenerator targetPackage="???" targetProject="???" /> <daoGenerator type="IBATIS" targetPackage="???" targetProject="???" /> <table schema="???" tableName="???"> <generatedKey column="???" sqlStatement="???" identity="???"> <columnOverride column="???" property="???" /> </table></abatorContext></abatorConfiguration>我们需要做的是替换一些???:1. 填写driverClass(jdbc驱动,例如MySql的就是com.mysql.jdbc.Driver)2. 填写connectionURL(连接字符串,例如MySql的就是jdbc:mysql://localhost:3306/ibatis)3. 填写classPathEntry的location(jdbc驱动jar包的位置,例如:lib/mysql-connector-java-3.1.5-gamma-bin.jar)4. 填写javaModelGenerator,生成的DTO(java model 类) targetPackage:目标包的位置,如 com.etong.test.daomain targetProject:目标源文件夹位置,如:../test/src/main/java/5. 填写sqlMapGenerator ,生成的xml sqlmap的相关配置 targetPackage:目标位置,如 .表示放在该目标源文件夹的根目录下. targetProject:目标源文件夹位置,如:../test/src/main/resources/6. 填写daoGenerator ,生成的DAO的相关配置 type:生成的dao实现的类型,如果你使用spring的话写SPRING,否则写IBATIS targetPackage:目标位置,如 com.etong.test.dao targetProject:目标源文件夹位置,如:../test/src/main/java/7. 配置相关数据库的表 schema:数据库schema (如果是oracle就是填写数据库的用户名,可以不填) tableName:表名  generatedKey:来告诉abator那些列需要自动返回值(当插入的时候可以返回插入记录的主键,这对有外键的数据库极其有用)identity默认为false columnOverride:重写的列,列名重写.【注意事项】: 1.Abator工具生成的DAO实现中,引用SqlMap Statements时默认使用namespace,即namespace.statements; 2.Statements ID以abatorgenerated_开头时,默认为是自动生成的elements,下次会重新生成(覆盖)该elements; 3.在 jdbcConnection 中设置要mapping的数据库的jdbc连接classPathEntry 是你的jdbc driver类路径 4.javaModelGenerator,sqlMapGenerator,daoGenerator 分别设置 java dataObject、sql mapping文件和DAO 接口、实现类的生成位置:targetPackage 目标包,targetProject:eclipse项目 5.daoGenerator 中可以设置属性  type: ibatis 或 spring 指定生成的dao实现类是使用com.ibatis.dao.client.template.SqlMapDaoTemplate还是org.springframework.orm.ibatis.support.SqlMapClientDaoSupport 6.table 中 tableName 指定要处理的表名  可以有多个table  7.table中可以包含子元素 generatedKey: 使Insert方法可以返回值--由指定的column mapping  8.generatedKey中的sqlStatement属性可以是获取sequence的SQL,也可以是获取自增值的SQL   比如:Oracle的 select theSequence.nextVal from dual   SQLServer的 SELECT @@IDENTITY as column_name


  

例:

<?xml version="1.0" encoding="UTF-8" ?><!DOCTYPE abatorConfiguration PUBLIC "-//Apache Software Foundation//DTD Abator for iBATIS Configuration 1.0//EN" "http://ibatis.apache.org/dtd/abator-config_1_0.dtd" ><abatorConfiguration >  <abatorContext >    <jdbcConnection driverClass="com.mysql.jdbc.Driver" connectionURL="jdbc:mysql://localhost:3306/rms"         userId="root" password="11111111" >      <classPathEntry location="D:/hurry/Workspaces/MyEclipse10/rms/WebRoot/WEB-INF/testLib/mysql-connector-java-5.1.18-bin.jar" />    </jdbcConnection>    <javaModelGenerator targetPackage="com.zltd" targetProject="rms" />    <sqlMapGenerator targetPackage="com.zltd" targetProject="rms" />    <daoGenerator targetPackage="com.zltd" targetProject="rms" type="SPRING" />    <!-- <table schema="" tableName="T_AFN_0C_F1" >        <columnOverride column="???" property="???" />    </table> -->    <table schema="" tableName="tb_log" ></table>    <table schema="" tableName="tb_error" ></table>    <table schema="" tableName="tb_user" ></table>    <table schema="" tableName="tb_user_role" ></table>    <table schema="" tableName="tb_user_orgnazation" ></table>    <table schema="" tableName="tb_role_resouce_operation" ></table>    <table schema="" tableName="tb_role" ></table>    <table schema="" tableName="tb_orgnazation" ></table>    <table schema="" tableName="tb_role_resouce" ></table>    <table schema="" tableName="tb_resouce" ></table>    <table schema="" tableName="tb_resouce_operation" ></table>    <table schema="" tableName="tb_operation" ></table>    <table schema="" tableName="tb_dictionary" ></table>    <table schema="" tableName="tb_asset_change" ></table>    <table schema="" tableName="tb_asset" ></table>    <table schema="" tableName="tb_app" ></table>      </abatorContext></abatorConfiguration>


 

 

热点排行