昨天下了Jpetstore要学习一下,于是在今天到iBATIS的官网上先看了看文档
发现SQL MAPS的确是个值得学习并应用的好东西
------
iBATIS可以说非常容易上手,只需要懂得JavaBeans, XML 和 SQL就可以顺利应用了
这也是iBATIS的魅力所在(我是这么觉得的呵呵)
iBATIS在JavaObject和数据库对应上提供了一个非常简单并且灵活的解决方案。
我们只需要使用纯正的SQL语句就可以实现从数据库到JavaObject的转换了,而不用再去写JDBC代码了
仅仅如此就帮助我们在代码上节省了不少时间吧
iBATIS SQL MAPS需要一个简单的XML描述文件,来对应数据库与JavaObjec之间的关系
等等优点
下面是从iBATIS网站上摘下来的有关iBATIS的几点特性
10Works with any database that has a JDBC driver (no plugins required)9Configurable caching (including dependencies)8Local and Global transaction support and management (JTA)7Simple XML mapping document structure 6Supports Map, Collection, List and Primitive Wrappers (Integer, String etc.)5Supports JavaBeans classes (get/set methods)4Supports complex object mappings (populating lists, complex object models etc.)3Object models are never perfect (no changes required!)2Database designs are never perfect (no changes required!)1You already know SQL, why waste time learning something else?
------
通过下面简单的例子,相信对iBATIS还陌生的同仁们一定会激动不以了,想马上就练练手了呵呵
环境:
所需要的类库:
IBATIS公用的工具类-ibatis-common.jar
IBATIS SQL Maps框架-ibatis-sqlmap.jar
一个简单的SqlMap定义片段:
<select id="getAddress" parameterClass="int"
resultClass="examples.domain.Address">
select
ADR_ID as id,
ADR_DESCRIPTION as description,
ADR_STREET as street,
ADR_CITY as city,
ADR_PROVINCE as province,
ADR_POSTAL_CODE as postalCode
from ADDRESS
where ADR_ID = #value#
</select>
在具体实现中的代码:
Integer pk = new Integer(5);
Address address = (Address)sqlMap.queryForObject("getAddress", pk);
就是这么简单的完成了。
------
更多的更好的信息可以去http://www.ibatis.com上找,中文的教程也有哦呵呵
本文地址:http://com.8s8s.com/it/it10621.htm