没有合适的资源?快使用搜索试试~ 我知道了~
温馨提示
试读
62页
Help make this documentation better… If you find this documentation lacking in any way, or missing documentation for a feature, then the best thing to do is learn about it and then write the documentation yourself! We accept public documentation contributions through our wiki at: http://opensource.atlassian.com/confluence/oss/display/IBATIS/Contribute+Documentation You’re the best author of this documentation, people like you have to read it!
资源推荐
资源详情
资源评论
iBATIS 3
User Guide
Warning about Copying Code from this Document
No, this is not a legal warning. It is one to help you keep your sanity. Modern word
processors do a great job of making text readable and formatted in an aesthetically
pleasing way. However, they also tend to completely ruin code examples by
inserting special characters, sometimes that look exactly the same as the one you
think you want. “Quotes” and hyphens are a perfect example –the quotes and
hyphen you see to the left will not work as quotes in an IDE or text editor, at least
not the way you intend.
So read this document, enjoy it and hopefully it is helpful to you. When it comes to
code examples, seek out the examples included with the download (including unit
tests etc.), or examples from the website or mailing list.
Help make this documentation better…
If you find this documentation lacking in any way, or missing documentation for a feature,
then the best thing to do is learn about it and then write the documentation yourself!
We accept public documentation contributions through our wiki at:
http://opensource.atlassian.com/confluence/oss/display/IBATIS/Contribute+Documentation
You’re the best author of this documentation, people like you have to read it!
Contents
What is iBATIS? ............................................................................................................................................. 5
Getting Started .............................................................................................................................................. 5
Building SqlSessionFactory from XML ....................................................................................................... 5
Building SqlSessionFactory without XML .................................................................................................. 6
Acquiring a SqlSession from SqlSessionFactory ........................................................................................ 6
Exploring Mapped SQL Statements .......................................................................................................... 7
A Note about Namespaces.................................................................................................................... 8
Scope and Lifecycle ................................................................................................................................... 9
Mapper Configuration XML ........................................................................................................................ 10
properties ................................................................................................................................................ 11
settings .................................................................................................................................................... 12
typeAliases .............................................................................................................................................. 13
typeHandlers ........................................................................................................................................... 14
objectFactory .......................................................................................................................................... 15
plugins ..................................................................................................................................................... 16
environments .......................................................................................................................................... 17
transactionManager ............................................................................................................................ 18
dataSource .......................................................................................................................................... 19
mappers .................................................................................................................................................. 21
SQL Map XML Files ...................................................................................................................................... 21
select ....................................................................................................................................................... 22
insert, update, delete .............................................................................................................................. 23
sql ............................................................................................................................................................ 26
Parameters .............................................................................................................................................. 26
iBATIS 3 - User Guide
15 February 2010 4
resultMap ................................................................................................................................................ 28
Advanced Result Mapping .................................................................................................................. 30
id, result .............................................................................................................................................. 32
Supported JDBC Types ........................................................................................................................ 33
constructor .......................................................................................................................................... 33
association .......................................................................................................................................... 34
collection ............................................................................................................................................. 37
discriminator ....................................................................................................................................... 39
cache ....................................................................................................................................................... 41
Using a Custom Cache ......................................................................................................................... 42
cache-ref ................................................................................................................................................. 43
Dynamic SQL ............................................................................................................................................... 44
if .............................................................................................................................................................. 44
choose, when, otherwise ........................................................................................................................ 45
trim, where, set ....................................................................................................................................... 45
foreach .................................................................................................................................................... 47
Java API ....................................................................................................................................................... 48
Directory Structure ................................................................................................................................. 48
SqlSessions .............................................................................................................................................. 49
SqlSessionFactoryBuilder .................................................................................................................... 49
SqlSessionFactory................................................................................................................................ 51
SqlSession ............................................................................................................................................ 53
SelectBuilder ............................................................................................................................................... 59
iBATIS 3 - User Guide
15 February 2010 5
What is iBATIS?
iBATIS is a first class persistence framework with support for custom SQL, stored procedures and
advanced mappings. iBATIS eliminates almost all of the JDBC code and manual setting of parameters
and retrieval of results. iBATIS can use simple XML or Annotations for configuration and map primitives,
Map interfaces and Java POJOs (Plain Old Java Objects) to database records.
Getting Started
Every iBATIS application centers around an instance of SqlSessionFactory. A SqlSessionFactory instance
can be acquired by using the SqlSessionFactoryBuilder. SqlSessionFactoryBuilder can build a
SqlSessionFactory instance from an XML configuration file, of from a custom prepared instance of the
Configuration class.
Building SqlSessionFactory from XML
Building a SqlSessionFactory instance from an XML file is very simple. It is recommended that you use a
classpath resource for this configuration, but you could use any Reader instance, including one created
from a literal file path or a file:// URL. iBATIS includes a utility class, called Resources, that contains a
number of methods that make it simpler to load resources from the classpath and other locations.
String resource = "org/apache/ibatis/example/Configuration.xml";
Reader reader = Resources.getResourceAsReader(resource);
sqlMapper = new SqlSessionFactoryBuilder().build(reader);
The configuration XML file contains settings for the core of the iBATIS system, including a DataSource for
acquiring database Connection instances, as well as a TransactionManager for determining how
transactions should be scoped and controlled. The full details of the XML configuration file can be found
later in this document, but here is a simple example:
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE configuration
PUBLIC "-//ibatis.apache.org//DTD Config 3.0//EN"
"http://ibatis.apache.org/dtd/ibatis-3-config.dtd">
<configuration>
<environments default="development">
<environment id="development">
<transactionManager type="JDBC"/>
<dataSource type="POOLED">
<property name="driver" value="${driver}"/>
<property name="url" value="${url}"/>
<property name="username" value="${username}"/>
<property name="password" value="${password}"/>
</dataSource>
</environment>
</environments>
<mappers>
<mapper resource="org/apache/ibatis/example/BlogMapper.xml"/>
</mappers>
</configuration>
剩余61页未读,继续阅读
资源评论
- rotakoa2012-10-26就是找这个,要是中文的就更好了
yang_xiang
- 粉丝: 1
- 资源: 12
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功