没有合适的资源?快使用搜索试试~ 我知道了~
首页iBATIS 3.0入门与新特性学习
iBATIS 3.0 User Guide 是一本针对 iBATIS 3.0 版本的详细指南,它旨在帮助用户理解和掌握这个数据库持久层框架。相比于之前的 iBATIS 2.0,iBATIS 3.0引入了全新的标记语言,这在技术上是一个重要的升级,对于那些寻求提升数据库操作效率和代码可读性的人来说,是不可或缺的学习资料。 该指南的标题强调了它是一份实用的工具,而不是法律意义上的警告。然而,作者提醒读者要注意一个常见的问题,即现代文本处理软件在呈现文档时,可能会插入特殊字符,导致代码示例中的引号、连字符等符号在实际编程环境中无法正常工作。因此,阅读指南时,尤其是遇到代码示例部分,建议查阅下载文件中提供的例子(包括单元测试),或者参考官方网站和邮件列表中的示例,以确保正确理解并应用到实践中。 作者鼓励读者积极参与文档的改进,如果发现文档存在不足或者某个功能缺乏详细的指导,最好的解决方案是深入学习相关技术,并将其转化为文档贡献给开源社区。iBATIS官方支持通过Atlassian的开源项目wiki平台参与文档贡献,链接地址为 <http://opensource.atlassian.com/confluence/oss/display/IBATIS/Contribute+Documentation>。 iBATIS 3.0 User Guide 是一个既实用又有助于提升开发者技能的资源,它不仅提供了全面的技术讲解,还提倡互动式的学习和文档建设,使得用户不仅能获取知识,还能参与到技术的持续发展中。
资源详情
资源推荐
iBATIS 3 - User Guide
23 January 2010 11
<property name="username" value="dev_user"/>
<property name="password" value="F2Fa3!33TYyg"/>
</properties>
The properties can then be used throughout the configuration files to substitute values that need to be
dynamically configured. For example:
<dataSource type="POOLED">
<property name="driver" value="${driver}"/>
<property name="url" value="${url}"/>
<property name="username" value="${username}"/>
<property name="password" value="${password}"/>
</dataSource>
The username and password in this example will be replaced by the values set in the properties
elements. The driver and url properties would be replaced with values contained from the
config.properties file. This provides a lot of options for configuration.
Properties can also be passed into the SqlSessionBuilder.build() methods. For example:
SqlSessionFactory factory =
sqlSessionFactoryBuilder.build(reader, props);
// ... or ...
SqlSessionFactory factory =
sqlSessionFactoryBuilder.build(reader, environment, props);
If a property exists in more than one of these places, iBATIS loads them in the following order:
• Properties specified in the body of the properties element are read first,
• Properties loaded from the classpath resource or url attributes of the properties element are
read second, and override any duplicate properties already specified ,
• Properties passed as a method parameter are read last, and override any duplicate properties
that may have been loaded from the properties body and the resource/url attributes.
Thus, the highest priority properties are those passed in as a method parameter, followed by
resource/url attributes and finally the properties specified in the body of the properties element.
settings
These are extremely important tweaks that modify the way that iBATIS behaves at runtime. The
following table describes the settings, their meanings and their default values.
Setting
Description
Valid Values
Default
cacheEnabled
Globally ena
bles or disables any caches
configured in any mapper under this
configuration.
true | false
true
lazyLoadingEnabled
Globally enables or disables lazy loading.
true | false
true
iBATIS 3 - User Guide
23 January 2010 12
When disabled, all associations will be eagerly
loaded.
multipleResultSetsEn
abled
Allows or disallows multiple ResultSets to be
returned from a single statement (compatible
driver required).
true | false
true
useColumnLabel
Uses the column label instead of the column
name. Different drivers behave differently in
this respect. Refer to the driver
documentation, or test out both modes to
determine how your driver behaves.
true | false
true
useGeneratedKeys
Allows JDBC support for generated keys. A
compatible driver is required. This setting
forces generated keys to be used if set to
true, as some drivers deny compatibility but
still work (e.g. Derby).
true | false
False
autoMappingBehavior
Specifies if and how iBATIS should
automatically map columns to
fields/properties. PARTIAL will only auto-
map simple, non-nested results. FULL will
auto-map result mappings of any complexity
(nested or otherwise).
NONE,
PARTIAL,
FULL
PARTIAL
defaultExecutorType
Configures the default executor. SIMPLE
executor does nothing special. REUSE
executor reuses prepared statements. BATCH
executor reuses statements and batches
updates.
SIMPLE
REUSE
BATCH
SIMPLE
defaultStatementTimeout
Sets the timeout that determines how long
the driver will wait for a response from the
database.
Any positive
integer
Not Set
(null)
An example of the settings element fully configured is as follows:
<settings>
<setting name="cacheEnabled" value="true"/>
<setting name="lazyLoadingEnabled" value="true"/>
<setting name="multipleResultSetsEnabled" value="true"/>
<setting name="useColumnLabel" value="true"/>
<setting name="useGeneratedKeys" value="false"/>
<setting name="enhancementEnabled" value="false"/>
<setting name="defaultExecutorType" value="SIMPLE"/>
<setting name="defaultStatementTimeout" value="25000"/>
</settings>
typeAliases
A type alias is simply a shorter name for a Java type. It's only relevant to the XML configuration and
simply exists to reduce redundant typing of fully qualified classnames. For example:
<typeAliases>
iBATIS 3 - User Guide
23 January 2010 13
<typeAlias alias="Author" type="domain.blog.Author"/>
<typeAlias alias="Blog" type="domain.blog.Blog"/>
<typeAlias alias="Comment" type="domain.blog.Comment"/>
<typeAlias alias="Post" type="domain.blog.Post"/>
<typeAlias alias="Section" type="domain.blog.Section"/>
<typeAlias alias="Tag" type="domain.blog.Tag"/>
</typeAliases>
With this configuration, “Blog” can now be used anywhere that “domain.blog.Blog” could be.
typeHandlers
Whenever iBATIS sets a parameter on a PreparedStatement or retrieves a value from a ResultSet, a
TypeHandler is used to retrieve the value in a means appropriate to the Java type. The following table
describes the default TypeHandlers.
Type Handler
Java Types
JDBC Types
BooleanTypeHandler
Boolean, boolean
Any compatible BOOLEAN
ByteTypeHandler
Byte, byte
Any compatible NUMERIC or B
YTE
ShortTypeHandler
Short, short
Any compatible NUMERIC or SHORT INTEGER
IntegerTypeHandler
Integer, int
Any compatible NUMERIC or INTEGER
LongTypeHandler
Long, long
Any compatible NUMERIC or LONG INTEGER
FloatTypeHandler
Float, float
Any compatible N
UMERIC or FLOAT
DoubleTypeHandler
Double, double
Any compatible NUMERIC or DOUBLE
BigDecimalTypeHandler
BigDecimal
Any compatible NUMERIC or DECIMAL
StringTypeHandler
String
CHAR, VARCHAR
ClobTypeHandler
String
CLOB, LONGVARCHAR
NStringTypeHandler
Str
ing
NVARCHAR, NCHAR
NClobTypeHandler
String
NCLOB
ByteArrayTypeHandler
byte[]
Any compatible byte stream type
BlobTypeHandler
byte[]
BLOB, LONGVARBINARY
DateTypeHandler
Date (java.util)
TIMESTAMP
DateOnlyTypeHandler
Date (java.util)
DATE
TimeOnlyType
Handler
Date (java.util)
TIME
SqlTimestampTypeHandler
Timestamp (java.sql)
TIMESTAMP
SqlDateTypeHadler
Date (java.sql)
DATE
SqlTimeTypeHandler
Time (java.sql)
TIME
ObjectTypeHandler
Any
OTHER, or unspecified
EnumTypeHandler
Enumeration Type
VARCHAR
–
any string compatible type, as the
code is stored (not the index).
You can override the type handlers or create your own to deal with unsupported or non-standard types.
To do so, simply implementing the TypeHandler interface (org.apache.ibatis.type) and map your new
TypeHandler class to a Java type, and optionally a JDBC type. For example:
// ExampleTypeHandler.java
public class ExampleTypeHandler implements TypeHandler {
剩余60页未读,继续阅读
守护神ZHi
- 粉丝: 0
- 资源: 3
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
最新资源
- Hadoop生态系统与MapReduce详解
- MDS系列三相整流桥模块技术规格与特性
- MFC编程:指针与句柄获取全面解析
- LM06:多模4G高速数据模块,支持GSM至TD-LTE
- 使用Gradle与Nexus构建私有仓库
- JAVA编程规范指南:命名规则与文件样式
- EMC VNX5500 存储系统日常维护指南
- 大数据驱动的互联网用户体验深度管理策略
- 改进型Booth算法:32位浮点阵列乘法器的高速设计与算法比较
- H3CNE网络认证重点知识整理
- Linux环境下MongoDB的详细安装教程
- 压缩文法的等价变换与多余规则删除
- BRMS入门指南:JBOSS安装与基础操作详解
- Win7环境下Android开发环境配置全攻略
- SHT10 C语言程序与LCD1602显示实例及精度校准
- 反垃圾邮件技术:现状与前景
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功