最近在做接口自动化平台开发时,接触到 ibatis框架,发现每个接口实现的代码逻辑和流程基本上一致。DAO对应数据库操作,DTO、FORM对应数据表在java中的对象映射,通过一个xml文件映射出数据库表action和对象action。就在想能不能找到一种自动生成代码的方法提高开发效率,果然在网上搜索到一个eclipse插件 ibators,下面介绍下ibators 的基本使用方法。
1.Ibators安装:
eclipse菜单 help-->
software updates-->
add site-->(填入在线安装地址:http://ibatis.apache.org/tools/ibator
-->一直下一步安装
2.建立配置文件,在项目中右键打开文件建立向导找到apache ibatis ibator configuration file

3.修改配置文件
原始配置文件如下

修改后的配置文件如下

4.自动生成的代码
点击右键-->点击Generate ibatis artifacts,这样就应该能生成对应的package和类

最终自动生成了DTO.FORM DAO以及xml文件,其中 DTO FORM不需要修改可以直接使用


5.根据需求修改代码
注意点:

需要指定mysql驱动文件目录
参考网站:
http://ibatis.apache.org/docs/tools/abator/
总体来说使用ibators在开发ibatis框架代码时大大提高了工作效率,不用分析数据库表结构,不用自己构造model,生成的数据库映射关系也在简单修改后可以直接使用,数据表字段越多效率提升越高
网友评论