发表时间:2008-06-24
前两天在javaeye上闲逛,无意间看到iBATIS也有代码生成的工具,这两天一直没抽着时间试试,今天利用15分钟时间试用了下,感觉还是不错的,很简单也很实用。
iBATOR下载:http://ibatis.apache.org/ibator.html
它提供了多种格式的下载,大家有兴趣可以逐一下载研究,我用的是eclipse的插件。eclipse安装插件大家应该都明白了。呵呵
装完之后,新建一个Java
Project名为:Ibatis。工程建好好在此工程中新建配置文件:abatorConfig.xml。具体为:File-New-Abator For
iBATIS ConfigurationFile.
根据需要修改此文件。我的配置为:
<?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="org.gjt.mm.mysql.Driver"
connectionURL="jdbc:mysql://localhost:3306/fsc" userId="root"
password="password3401" >
<classPathEntry
location="D:\mysql-connector-java-5.0.6-bin.jar" />
</jdbcConnection>
<javaModelGenerator
targetPackage="test.model" targetProject="Ibatis\src" />
<sqlMapGenerator targetPackage="test.xml" targetProject="Ibatis\src" />
<table schema="fsc" tableName="test" >
<generatedKey column="id" sqlStatement="MySQL" identity="true" />
<columnOverride column="address" property="addr" />
</table>
</abatorContext>
</abatorConfiguration>
到此,一切准备工作ok
下面生成model及各种配置文件。
在abatorConfig.xml文件上鼠标右键,“Generate
iBATIS Artifacts”即可。
这样会在你指定的路径下生成model文件。
唯一遗憾的是不支持annotiation。
总的来说感觉还是不错的。
官方文档:http://ibatis.apache.org/docs/tools/abator/
-------------------------------------------------------------------
Introduction to iBATOR
iBATOR is a code generator for iBATIS. iBATOR will introspect a database table (or many tables)
and will generate iBATIS artifacts that can be used to access the table(s). This
abates some of the initial nuisance of setting up objects and configuration
files to interact with database tables. iBATOR seeks
to make a major impact on the large percentage of database operations that are
simple CRUD (Create, Retrieve, Update, Delete). You will still need to hand code
SQL and objects for custom queries, or stored procedures.
iBATOR will generate:
- SqlMap XML Files
- Java Classes to match the primary key and fields of the table(s)
- DAO Classes that use the above objects (optional)
iBATOR can run as a standalone JAR file, or as an
Ant task, or as an Eclipse plugin.
iBATOR is currently under development. The legacy
version (Abator) is still available. If you have suggestions for the future of
iBATOR, please feel free to send them to the Java
user's mailing list..
About the Name
iBATOR
News
(April 14, 2008) Due to a trade registration dispute, Abator is renamed to
iBATOR. iBATOR is currently under development. The initial source code drop can
be checked out from SVN at http://svn.apache.org/repos/asf/ibatis/trunk/java/tools/ibator/
(March 20, 2008) Updated Abator and the Eclipse plugin to version 1.1.0. This
is an extensive update that includes quite a few minor enhancements, two major
enhancements (two new methods can be generated), and a few bug fixes. See the
What's New? section of the online documentation for full details.
(August 20, 2006) Updated Abator and the Eclipse plugin to version 1.0.0.
This is an extensive update that includes many new features including the
ability to generate code for Java 5, generate different types of domain models,
and hugely improved "by example" methods. See the "What's New?" section of the
online documentation for full details.
iBATOR Development
- iBATOR requires JRE version 5.0 or higher
- iBATOR generates code that depends on iBATIS version 2.2.0 or higher
- iBATOR does not include the Legacy generator set from Abator
- The format of the XML configuration file is slightly different and abator*
elements are renamed to ibator*.
The code generated by iBATOR will be 100%
compatible with code generated by Abator. We are simply taking this opportunity
to clean up some of the API that is a little cumbersome.
Legacy
Abator Software Downloads and Documentation
Eclipse Plugin
Documentation for Abator is integrated into the Eclipse help system.
Requirements
- Eclipse 3.2 or higher (Note: if you are stuck on Eclipse 3.0, or version 6.0
of the Rational development tools, the prior version of the plugin is still
available on the update site) - JDK 1.4 or Higher
Automatic Eclipse
Install
- Take the "Help>Software Updates>Find and Install" Menu Option
- Select the "Search for new features to install" radio button, press "Next"
- Press the "New Remote Site" button
- Enter the following information: Name:Abator for Eclipse Update
SiteURL:http://ibatis.apache.org/tools/abator - Press OK
- Check the box next to "Abator for Eclipse Update Site"
- Follow the remainder of the install wizard
Manual Eclipse
Install
- Take the "Help>Software Updates>Find and Install" Menu Option
- Select the "Search for new features to install" radio button, press "Next"
- Press the "New Local Site" button
- Navigate to the location where you unzipped the file.
- Press OK
- Follow the remainder of the install wizard
<javaTypeResolver >
<property name="forceBigDecimals"
value="false" />
</javaTypeResolver>
没有评论:
发表评论