这里使用的是ibator做为ibatisEclipse插件,ibator的主页是:http://ibatis.apache.org/ibator.htmlhtml
它提供两种方式:一种是Eclipse插件,一种是独立运行。java
目前针对Eclipse的版本有两个版本,sql
1.2.1能运行在:数据库
· Eclipse 3.4.1 or higherapache
· JDK 5.0 or Higheroracle
· 它的Eclipse插件URL下载地址为:http://ibatis.apache.org/tools/ibatordom
1.1.0运行在:eclipse
· Eclipse 3.2 or higheride
· JDK 1.4 or Highersqlserver
· 它的Eclipse插件URL下载地址为:http://ibatis.apache.org/tools/abator
注意: 版本问题,笔者开始用的是myEclipse6.0.1,是eclipse 3.3.1平台,装了1.2.1怎么也不能用,调查才发现,不要由于版本而影响做用。
新建一个工程,而后在该工程下新建文件,截图以下:(若是这里没有请到other..中找,截图如右:)
点击后就会新建一个文件:abatorConfig.xml。
如下是1.1.0的写法,供你们参照:
<?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.microsoft.jdbc.sqlserver.SQLServerDriver" connectionURL="jdbc:microsoft:sqlserver://127.0.0.1:1433;DatabaseName=cmspro" userId="cmspro" password="cmspro" > <classPathEntry location="D:\POM\project\msbase.jar" /> <classPathEntry location="D:\POM\project\mssqlserver.jar"/> <classPathEntry location="D:\POM\project\msutil.jar" /> </jdbcConnection> <javaModelGenerator targetPackage="com.ucap.account.model" targetProject="account-service-impl" /> <sqlMapGenerator targetPackage="resources.sqlmaps" targetProject="account-service-impl" /> <daoGenerator targetPackage="com.ucap.account.dao" targetProject="account-service-impl" type="GENERIC-CI" /> <table tableName="cmspro_channel_privilege" domainObjectName="ChannelPrivilege"/> </abatorContext> </abatorConfiguration>
这里<table>标签中的domainObjectName,是用来从新命名类名。
如下是1.2.1的写法,供你们参照:
<?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE ibatorConfiguration PUBLIC "-//Apache Software Foundation//DTD Apache iBATIS Ibator Configuration 1.0//EN" "http://ibatis.apache.org/dtd/ibator-config_1_0.dtd "> <ibatorConfiguration> <!-- url 指定属性文件绝对路径。注意与指定数据库jdbc驱动jar包路径的区别哈。 可使用${property}的格式引用属性文件中的属性值。 <properties url="D:\WorkSpace\SSIStudy\ibator-config.properties"/> --> <!-- classPathEntry 指定数据库jdbc驱动jar包的绝对路径。 可为为空 The full path name of a JAR/ZIP file to add to the classpath, or a directory to add to the classpath --> <classPathEntry location="D:\WorkSpace\SSIStudy\WebRoot\WEB-INF\lib" /> <!-- id 这个id能够在使用命令行运行Abator时指定,以单独处理某一个ibatorContext targetRuntime Ibatis2Java5 生成适合JDK5.0的类,另外一个选项是 Ibatis2Java2,生成适合Java2的类。 --> <ibatorContext id="SSIStudy" targetRuntime="Ibatis2Java2"> <!-- ibatorPlugin 继承自IbatorPluginAdapter,包名必须是 org.apache.ibatis.ibator.plugins,具体实现能够参考官方文档 必须有替换和被替换字符属性。 能够没有 --> <!-- <ibatorPlugin type="org.apache.ibatis.ibator.plugins.RenameExampleClassPlugin"> <property name="searchString" value="Example$" /> <property name="replaceString" value="Criteria" /> </ibatorPlugin> driverClass 数据库驱动类 这里链接sqlserver2000 connectionURL 数据库链接地址 userId 用户 password 密码 还可使用如下格式添加数据库的其余链接属性 <property name="" value=""/> --> <jdbcConnection driverClass="com.microsoft.jdbc.sqlserver.SQLServerDriver" connectionURL="jdbc:microsoft:sqlserver://localhost:1433;DatabaseName=demo" userId="sa" password="sa" > </jdbcConnection> <javaTypeResolver > <!-- 默认false,把JDBC DECIMAL 和 NUMERIC 类型解析为 Integer true,把JDBC DECIMAL 和 NUMERIC 类型解析为java.math.BigDecimal --> <property name="forceBigDecimals" value="false" /> </javaTypeResolver> <!-- //When running outside of an IDE environment like Eclipse, Ibator interprets the targetProject and targetPackage attributes in all XML configurations as follows targetProject 生成的Java Bean放置在哪一个项目的哪一个目录下 targetPackage 生成的Java Bean的包名 一个有用的属性 从数据库返回的值被清理先后的空格 <property name="trimStrings" value="true" /> 是否在包名后加上scheme名称 <property name="enableSubPackages" value="false" /> --> <javaModelGenerator targetPackage="cn.per.jiabeis.model" targetProject="D:\WorkSpace\SSIStudy\src"> <property name="enableSubPackages" value="true" /> <property name="trimStrings" value="true" /> </javaModelGenerator> <!-- targetProject 生成的 SqlMap.xml 文件放置在哪一个项目的哪一个目录下 targetPackage 生成的 SqlMap.xml 文件的包名 <property name="enableSubPackages" value="false" /> 是否在包名后加上scheme名称 --> <sqlMapGenerator targetPackage="cn.per.jiabeis.model.config" targetProject="D:\WorkSpace\SSIStudy\src"> <property name="enableSubPackages" value="true" /> </sqlMapGenerator> <!-- targetProject 生成的 dao类文件放置在哪一个项目的哪一个目录下 targetPackage 生成的 dao类文件的包名 <property name="enableSubPackages" value="false" /> 是否在包名后加上scheme名称 type 生成dao文件的类型,可选择IBATIS、SPRING、GENERIC-CI、GENERIC-SI。默认使用GENERIC-CI dao类在构造器中获取 SqlMapClient。 --> <daoGenerator targetPackage="cn.per.jiabeis.dao" targetProject="D:\WorkSpace\SSIStudy\src" type="IBATIS"> <property name="enableSubPackages" value="true" /> </daoGenerator> <!-- tableName 数据库代表,听说能够包含SQL通配符%和_。 domainObjectName 数据库表对应的数据对象名称,默认使用表名做为对象名称。 --> <table tableName="student" domainObjectName="Student"> <!-- 对象的属性名是否使用字段名称,默认为true --> <property name="stuname" value="stuname"/> <!-- column 自增加或使用sequence生成的字段名 sqlStatement 生成字段的sql片断或其简称(参考官方文档) identity true表示后生成,false表示预生成 例如: postgresql:<generatedKey column="lid" sqlStatement="select nextval('tb000000producttype_lid_seq')" identity="false" /> sqlserver:<generatedKey column="lid" sqlStatement="SqlServer" identity="true" /> oracle:<generatedKey column="lid" sqlStatement="select tb000000producttype_lid_seq.nextval from dual" identity="false" /> MySql:<generatedKey column="lid" sqlStatement="MySql" identity="false" /> --> <generatedKey column="stuid" sqlStatement="SqlServer" identity="true"/> <!-- 数据库字段名称到对象属性名称的影射关系。就是一个替换处理。 --> <columnRenamingRule searchString="^CUST_" replaceString="" /> <!-- column 字段名 property 字段对应的属性名。(默认使用字段名的) javaType 对应的Java类型 jdbcType 对应的jdbc类型 这里的设置覆写javaTypeResolver中的指定 --> <columnOverride column="DATE_FIELD" property="startDate" /> <!-- column 须要忽略的数据库字段 --> <ignoreColumn column="FRED" /> </table> <table tableName="teacher"/> <table tableName="course"/> <table tableName="stu_course"/> </ibatorContext> </ibatorConfiguration>
以上书写好xml后,请鼠标右键点击该xml文件生成Artifacts。