!
!
!
!
!
!
!
!
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:
"##$%&&'$()*'+,-(./#0/**1/).-'2&-')30+()-(&'**&41*$0/5&67896:&;')#,1<+#(=>'-+2()#/#1')!
?'+@,(!#"(!<(*#!/+#"',!'3!#"1 * !4'-+2()#/#1')A!$('$0(!01B(!5'+!"/C(!#'!,(/4!1#D
Contents!
E"/#!1*!17896:F ............................................................................................................................................ G'
H(##1)I!:#/,#(4 ............................................................................................................................................ G'
7+1041)I!:J0:(**1')K/-#',5!3,'2!LMN...................................................................................................... G'
7+1041)I!:J0:(**1')K/-#',5!O1#"'+#!LMN................................................................................................. P '
8-J+1,1)I!/!:J0:(**1')!3,'2!:J0:(**1')K/-#',5 ....................................................................................... P'
QR$0',1)I!M/$$(4!:SN!:#/#(2()#* ......................................................................................................... T'
8!U'#(!/<'+#!U/2(*$/-(* .................................................................................................................. V'
:-'$(!/)4!N13(-5-0(.................................................................................................................................. W'
M/$$(,!;')31I+,/#1')!LMN ....................................................................................................................... XY'
$,'$(,#1(* .............................................................................................................................................. XY'
*(##1)I*................................................................................................................................................... XX'
#5$(801/*(*............................................................................................................................................. XZ'
#5$([/)40(,*.......................................................................................................................................... X\'
'<](-#K/-#',5 ......................................................................................................................................... X^'
$0+I1)*.................................................................................................................................................... XG'
()C1,')2()#*......................................................................................................................................... XP'
#,/)*/-#1')M/)/I(, .......................................................................................................................... XT'
4/#/:'+,-(......................................................................................................................................... XV'
2/$$(,* ................................................................................................................................................. ZY'
:SN!M/$!LMN!K10(*..................................................................................................................................... ZY'
*(0(-#...................................................................................................................................................... ZX'
1)*(,#A!+$4/#(A!4(0(#( ............................................................................................................................ ZZ'
*J0........................................................................................................................................................... ZG'
_/,/2(#(,*............................................................................................................................................. ZG'
17896:!\!`!a*(,!H+14(! !
XX!b-#'<(,!ZYYW! !^!
,(*+0#M/$............................................................................................................................................... ZT'
84C/)-(4!c(*+0#!M/$$1)I ................................................................................................................. ZW'
14A!,(*+0# ............................................................................................................................................. \X'
:+$$',#(4!d>7;!95$(* ....................................................................................................................... \X'
-')*#,+-#', ........................................................................................................................................ \Z'
/**'-1/#1') ......................................................................................................................................... \\'
-'00(-#1')............................................................................................................................................ \P'
41*-,121)/#',...................................................................................................................................... \V'
-/-"(...................................................................................................................................................... ^Y'
a*1)I!/!;+*#'2!;/-"(........................................................................................................................ ^X'
-/-"(`,(3 ................................................................................................................................................ ^Z'
>5)/21-!:SN .............................................................................................................................................. ^Z'
13 ............................................................................................................................................................. ^\'
-"''*(A!O"()A!'#"(,O1*(....................................................................................................................... ^\'
#,12A!O"(,(A!*(# ..................................................................................................................................... ^^'
3',(/-"................................................................................................................................................... ^P'
d/C/!8_6 ...................................................................................................................................................... ^T'
>1,(-#',5!:#,+-#+,( ................................................................................................................................ ^T'
:J0:(**1')*............................................................................................................................................. ^V'
:J0:(**1')K/-#',57+104(,................................................................................................................... ^V'
:J0:(**1')K/-#',5 .............................................................................................................................. GY'
:J0:(**1') .......................................................................................................................................... GX'
:(0(-#7+104(,.............................................................................................................................................. GT'
!
17896:!\!`!a*(,!H+14(! !
XX!b-#'<(,!ZYYW! !G!
What!is!iBATIS?!
17896:!1*!/!31,*#!-0/**!$(,*1*# ()-(!3,/2(O',B!O1#"!*+$$',#!3',!-+*#'2!:SNA!*#',(4!$ ,'-(4+,(*!/)4!
/4C/)-(4!2/$$1)I*.!!17896:!(0121)/#(*!/02'*#!/00!'3!#"(!d>7;!-'4(!/)4!2/)+/0!*(##1)I!'3!$/,/2(#(,*!
/)4!,(#,1(C/0!'3!,(*+0#*.!!17896:!-/)!+*( !* 1 2 $0(!LMN!',!8))'#/#1')*!3',!-')31I+,/#1')!/)4!2 / $ ! $ ,1 2 1 # 1 C( * A!
M/$!1)#(,3/-(*!/)4!d/C/!_bdb*!e_0/1)!b04!d/C/!b<](-#*f!#'!4/#/</*(!,(-',4*.!!
Getting!Started!
QC(,5!17896:!/$$01-/#1')!-()#(,*!/,'+)4!/)!1)*#/)-(!'3!:J0:(**1')K/-#',5.!!8!:J0:(**1')K/-#',5!1)*#/)-(!
-/)!<(!/-J+1,(4!<5!+*1)I!#"(!:J0:(**1')K/-#',57+104(,.!!:J0:(**1') K/-#' ,57+ 104(,!-/) !<+ 104 !/!
:J0:(**1')K/-#',5!1)*#/)- (! 3, ' 2 ! / ) !L MN!-')31I+,/#1')!310(A!'3!3,'2!/!-+*#'2!$,($/,(4!1 ) * #/ )-(!'3!#"(!
;')31I+,/#1')!-0/**.!!!
Building!SqlSessionFactory!from!XML!
7+1041)I!/!:J0:(**1')K/-#',5!1)*#/)-(!3,'2!/)!LMN!310(!1*!C(,5!*12$0(.!!6#!1*!,(-'22()4(4!#"/#!5'+!+*(!/!
-0/**$/#"!,(*'+,-(!3',!#"1*!-' )31I+,/#1')A!<+#!5'+!-'+04!+*(!/)5!c(/4(,!1)*#/)- (A! 1 ) - 0+41)I!')(!-,(/#(4!
3,'2!/!01#(,/0!310(!$/#"!',!/!310(%&&!acN. ! !1 7 8 9 6: ! 1 ) - 0 + 4 ( * !/ !+#101#5!-0/**A!-/00(4!c(*'+,-(*A!#"/#!-')#/1)*!/!
)+2<(,!'3!2(#"'4*!#"/#!2/B(!1#!*12$0(,!#'!0'/4!,(*'+,-(*!3,'2!#"(!-0/**$/#"!/)4!'#"(,!0'-/#1')*.!!!
String resource = "org/apache/ibatis/example/Configuration.xml";
Reader reader = Resources.getResourceAsReader(resource);
sqlMapper = new SqlSessionFactoryBuilder().build(reader);
9"(!-')31I+,/#1')!LMN!310( !- ' )#/1)*!*(##1)I*!3',!#"(!-',(!'3!#"(!17896:!*5*#(2A!1)-0 + 41)I!/!>/#/:'+,-(!3',!
/-J+1,1)I!4/#/</*(!;'))(-#1')!1)*#/)-(*A!/*!O(00!/*!/!9 ,/ ) * / -# 1 ' )M/)/I(,!3',!4(#(,21)1)I!"'O!
#,/)*/-#1')*!*"'+04!<(!*-'$(4!/)4!-')#,'00(4.!!9"(!3+00!4(#/10*!'3!#" (!LMN !-' )31I+ ,/#1') !310(!-/) !<(!3' + )4 !
0/#(,!1)!#"1*!4'-+2()#A!<+#! " (, (! 1 *! / !* 1 2 $0(!(R/2$0(%!
<?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>