Abator automatically generates ibatis related configurations and classes

1. Abator automatically generates configuration: Abator automatically generates ibatis configuration file, mode, sqlMap, dao, bean instance  preparation:  1. Install Eclipse plug-in:       Eclipse3.1, jdk1.4 or above is required       to install the abator plug-in         eclipse menu bar on eclipse- -> help --> Software Updates --> Find And nstall...       Select "Search for new features to install" in the pop-up dialog box and click "next"      in the dialog box and click the button New Remort Site... In Fill in http://ibatis.apache.org/tools/abator in the URL input box in the pop-up dialog box, and write whatever you want in the Name input box.     Click Finish, install the plug-in, and then restart eclipse     2. Create a new Abator Configuration File in the eclipse project named: abatorConfig.xml (can be customized). After the generated xml is modified as follows: 










 

Xml code   Favorite code
  1. <!DOCTYPE abatorConfiguration PUBLIC "-//Apache Software Foundation//DTD Abator for iBATIS Configuration 1.0//EN" "http://ibatis.apache.org/dtd/abator-config_1_0.dtd" >  
  2. <abatorConfiguration >  
  3.   <abatorContext >  
  4.     <jdbcConnection driverClass="oracle.jdbc.driver.OracleDriver"   
  5.           connectionURL="jdbc:oracle:thin:@198.17.1.1:1521:ORCL" userId="untodo" password="password" >  
  6.       <classPathEntry location="E:\oracle\product\10.2.0\db_1\jdbc\lib\ojdbc14.jar" />  
  7.     </jdbcConnection>  
  8.     <javaModelGenerator targetPackage="com.mochasoft.model" targetProject="downAttachdemo/src">  
  9.       <property name="enableSubPackages" value="true" />   
  10.     </javaModelGenerator>  
  11.     <sqlMapGenerator targetPackage="sqlmap" targetProject="downAttachdemo/conf>  
  12.       <property name="enableSubPackages" value="true" />   
  13.     </sqlMapGenerator>  
  14.     <daoGenerator targetPackage="com.mochasoft.dao" targetProject="downAttachdemo/src" type="ibatis">  
  15.      <property name="enableSubPackages" value="true" />   
  16.     </daoGenerator>  
  17.     <table schema="untodo" tableName="APP" >  
  18.       <columnOverride column="SYS_ID" property="sysId" />  
  19.       <columnOverride column="SYS_NAME" property="sysName" />  
  20.     </table>  
  21.   </abatorContext>  
  22. </abatorConfiguration>  


3、在配置文件上点解右键,选择 “Generate iBatis Artifacts” 

说明:driverClass:数据库连接驱动类 
      connectionURL:数据库连接地址 
      userId:数据库用户 
      passwor:数据库密码 
      location:数据库驱动jar包地址(本地) 
      targetPachage:自动生成的包的地址,(可以是已建好的,也可以是未建的) 
      targetProject:自动生成的项目名 
      type:生成dao文件的类型,可选择IBATIS、SPRING、GENERIC-CI、GENERIC-SI。默认使用GENERIC-CI 

Xml代码   Favorite code
  1. <property name="enableSubPackages" value="false" />  

  是否在包名后加上scheme名称 
schema:Oracle的话填写用户名 
tableName:要生成的表名 
column:表字段名 
property:表映射生成类属性名 
talbe下的字段说明:   
   tableName 数据库表明,据说可以包含SQL通配符%和_。 
   domainObjectName 数据库表对应的数据对象名称,默认使用表名作为对象名称。 
      

Xml代码   Favorite code
  1. <property name="useActualColumnNames" value="true"/>   


对象的属性名是否使用字段名称 

Xml代码   Favorite code
  1. <generatedKey column="ID" sqlStatement="DB2" identity="true" />  

  
    column    自增长或使用sequence生成的字段名 
              sqlStatement 生成字段的sql片段或其简称(参考官方文档) 
              identity    true表示后生成,false表示预生成 
               例如: 

  

Sql代码   Favorite code
  1. postgresql:<generatedKey   
  2.                     column="lid"   
  3.                     sqlStatement="select nextval('tb000000producttype_lid_seq')"   
  4.                     identity="false" />   
  5.                 sqlserver:<generatedKey   
  6.                     column="lid"   
  7.                     sqlStatement="SqlServer"   
  8.                     identity="true" />   
  9.                 oracle:<generatedKey   
  10.                     column="lid"   
  11.                     sqlStatement="select tb000000producttype_lid_seq.nextval from dual"   
  12.                     identity="false" />   



Xml代码   Favorite code
  1. <columnOverride column="DATE_FIELD" property="startDate" />   


        column 字段名 
         property 字段对应的属性名。(默认使用字段名的) 
         javaType 对应的Java类型 
         jdbcType 对应的jdbc类型     
        这里的设置覆写javaTypeResolver中的指定 
   

Xml代码   Favorite code
  1. <ignoreColumn column="FRED" />   


  column database field to ignore  

Xml code   Favorite code
  1. <columnRenamingRule searchString="^CUST_" replaceString="" />   


  The mapping relationship between database field names and object property names. It's a replacement process.     

 

http://jadethao.iteye.com/blog/1725374

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=326333867&siteId=291194637
Recommended