ibatis eclipse plugin Abator配置使用简单说明

Automatic Eclipse Install

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

If you've not already installed Abator, then you can use the built in Eclipse install support by following these steps:

  1. Take the "Help>Software Updates>Find and Install" Menu Option
  2. Select the "Search for new features to install" radio button, press "Next"
  3. Press the "New Remote Site" button
  4. Enter the following information:
    Name:
    Abator for Eclipse Update Site
    URL:
    http://ibatis.apache.org/tools/abator
  5. Press OK
  6. Check the box next to "Abator for Eclipse Update Site"
  7. Follow the remainder of the install wizard

安装:
         eclipse自动安装url: http://ibatis.apache.org/tools/abator

下载操作视频

http://www.ithov.com/mov/

配置:
         安装好后将在New菜单中看到一个新的文件类型Abator for iBATIS Configuration File,这个是Abator的配置文件,new一个并修改配置文件,配置样式如下所示:

<? 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 ="Java5" >      <!--  TODO: Add Database Connection Information  -->
    
< jdbcConnection  driverClass ="oracle.jdbc.driver.OracleDriver"
        connectionURL
="jdbc:oracle:thin:@127.0.0.1:1521:orcl"
        userId
="user"
        password
="password" >
      
<!--  注意:以下的classPathEntry一定要设置,否则会出现Exception JDBC Driver的错误  -->
      
< classPathEntry  location ="D:/workspace/lib/ojdbc14_g.jar"   />
    
</ jdbcConnection >

    
< javaModelGenerator  targetPackage ="com.iamyy.test.ibatis.vo"  targetProject ="AbatorTest"   />
    
< sqlMapGenerator  targetPackage ="com.iamyy.test.ibatis.dao"  targetProject ="AbatorTest"   />
    
< daoGenerator  type ="IBATIS"  targetPackage ="com.iamyy.test.ibatis.dao"  targetProject ="AbatorTest"   />

    
< table  tableName ="T_Role"  domainObjectName ="Role" >
      
< generatedKey  column ="role_id"  identity ="true"  sqlStatement ="select s_role.nextval from dual" />
      
< columnOverride  column ="role_id"  property ="id"  javaType ="java.lang.String"  jdbcType ="VARCHAR" />
      
< columnOverride  column ="role_name"  property ="name"  javaType ="java.lang.String"  jdbcType ="VARCHAR"   />
    
</ table >

  
</ abatorContext >
</ abatorConfiguration >


   

abatorContext的一个属性generatorSet有3个选项Legacy、Java2、Java5,一般用Java5;

         Legacy:如果没有generatorSet属性的话,默认是Legacy。但并不推荐使用Legacy因为它在生成Example类(用于查询条件)的时候有很多限制,他将查询条件写在sqlMap配置文件中,将查询值写在Example中,这样就对修改产生一些困难。

         Java2和Java5:他们只支持iBATIS 2.20以上的版本。在以这个模式成生的Example文件中包含了查询条件和查询值。这样修改就方便多了,对于用join的select时的查询就更方 便了,自己可以定义查询条件,自由度高了很多(对于join的and查询可能还得自己修改一下Example代码)。对于or和and的应用Legacy 的限制就比较大了。

         <javaModelGenerator>、 <sqlMapGenerator>、 <daoGenerator>描述了个自生成的位置。<daoGenerator>中type属性则用来告诉abator生成的DAO是用于iBATIS还是SPRING等容器。

         <table>告诉abator生成那个table的sqlMap。

         <generatedKey>来告诉abator那些列需要自动返回值(当插入的时候可以返回插入记录的主键,这对有外键的数据库极其有用)identity默认为false,则在sqlMap配置文件中<selectKey>的位置在sql命令前面,所以identity应该改为true。根据数据库类型的不同sqlStatement属性取值也不同。


运行:

         右键单击配置文件,点击Generate iBatis Artifacts,生成文件。

         ps: 如果<daoGenerator>中type属性是ibatis的话,由于Abator生成的DAOImpl文件继承自com.ibatis.dao.client.template.SqlMapDaoTemplate,在ibatis ver. 2.3.0.677中会有错误提示,需酌情修改。
         ps的ps: 不建议使用自动生成的Example去操作数据,一是因为Example中生成的方法有拼写SQL之嫌不符合OO思想,二是拼写后SQL效率有待进一步考证,没仔细看,但至少看到not in语句,如果要使用的话至少要进行一些修改。(^-^)个人愚见。

 

 

你可能感兴趣的:(DAO,apache,eclipse,oracle,ibatis)