`
chhj_292
  • 浏览: 37011 次
  • 性别: Icon_minigender_1
  • 来自: 杭州
文章分类
社区版块
存档分类
最新评论

Ibator生成ibatis 配文件

阅读更多

Ibato r 生成ibatis 配置文件

 

作者:×××

日期:2009-06-08 15.03

版本:0.1

Ibator能给我们带来什么

由于使用Ibatis 时需要生成的配置文件较多,而且对于字段较多的表生成其 Ibatis 实体时容易出错,使用 Ibators 插件能减少我们很多枯燥的工作,提高正确性和准确率。

准备工作

Eclipse Platform   Version: 3.4.2 ;

Ibator官方网站 Ibator 1.2.1 ;

安装Ibator 插件,可以使用本地方式安装,也可以使用 Update side 方式安装,为了方便,这里使用 update side 方式安装(引自官网):

Automatic Eclipse Install

If you've already installed a prior version of Ibator, simply run the Eclipse Update tool and the new version will be found automatically.

If you've not previously installed Ibator, use the built in Eclipse install support by following these steps:

1.  Take the "Help>Software Updates..." Menu Option

2.  Select the "Available Software" Tab

3.  Press the "Add Site" button

4.  Enter the following information: Location,http://ibatis.apache.org/tools/ibator

5.  Press OK

6.  Check the box next to "Apache iBATIS Ibator Feature"

7.  Press the "Install" button

8.  Follow the remainder of the install wizard (restart you eclipse IDE)

插件安装成功之后,

在“File->New ”菜单里将会有一个新选项,如下图:

在鼠标右键上,也会有一个新的选项,如下图:

示例

步骤如下:

1.  生成ibatorConfig.xml 配置文件,关于配置文件详细注释参见: Introduction to Abator

2.  配置数据库连接(驱动,URL User Psd etc );

3.  配置Java Model Generator 参数;

4.  配置SQL Map Generator 参数;

5.  配置DAO Generator 参数;

6.  配置需要生成Ibatis 配置的表;

7.  “右键”选择“ ”完成操作;

 

完整示例配置文件如下:

< ibatorConfiguration >

< classPathEntry   location = "E:/workspace/antx/repository/jdbc/oracle/ojdbc14.jar"   />

< ibatorContext   id = "context1" >

< jdbcConnection   driverClass = "oracle.jdbc.driver.OracleDriver"

connectionURL = "jdbc:oracle:thin:@10.2.224.34:1521:aepdb"   userId = "core"

password = "core"   />

< javaModelGenerator   targetPackage = "com.alisoft.model"

targetProject = "test/src/" >

< property   name = "enableSubPackages"   value = "false"   />

< property   name = "trimStrings"   value = "true"   />

</ javaModelGenerator >

< sqlMapGenerator   targetPackage = "com.alisoft.model.sql"

targetProject = "test/src/" >

< property   name = "enableSubPackages"   value = "false"   />

</ sqlMapGenerator >

< daoGenerator   targetPackage = "com.alisoft.dao"

targetProject = "test/src/"   type = "GENERIC-CI" >

< property   name = "enableSubPackages"   value = "false"   />

</ daoGenerator >

< table   tableName = "ADMIN_USER"   domainObjectName = "Admin" / >

</ ibatorContext >

</ ibatorConfiguration >

补充说明:

1.  如果指定的 targetPackage 不存在,Ibator 会帮我们自动生成;

2.  根据官方文档描述," daoGenerator  "是一个可选配置,但是实际情况是不配置该选项 xml 验证能通过,但是会报一个类似空指针的错误;

3.  以上描述均在本人机器上测试通过;

分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics