MyBatis3UserGuide.docx
- 文档编号:12566463
- 上传时间:2023-04-20
- 格式:DOCX
- 页数:122
- 大小:63.24KB
MyBatis3UserGuide.docx
《MyBatis3UserGuide.docx》由会员分享,可在线阅读,更多相关《MyBatis3UserGuide.docx(122页珍藏版)》请在冰豆网上搜索。
MyBatis3UserGuide
MyBatis3
UserGuide
WarningaboutCopyingCodefromthisDocument
No,thisisnotalegalwarning.Itisonetohelpyoukeepyoursanity.Modernword
processorsdoagreatjobofmakingtextreadableandformattedinanaesthetically
pleasingway.However,theyalsotendtocompletelyruincodeexamplesby
insertingspecialcharacters,sometimesthatlookexactlythesameastheoneyou
thinkyouwant.“Quotes”andhyphensareaperfectexample–thequotesand
hyphenyouseetotheleftwillnotworkasquotesinanIDEortexteditor,atleast
notthewayyouintend.
Soreadthisdocument,enjoyitandhopefullyitishelpfultoyou.Whenitcomesto
codeexamples,seekouttheexamplesincludedwiththedownload(includingunit
testsetc.),orexamplesfromthewebsiteormailinglist.
Helpmakethisdocumentationbetter…
Ifyoufindthisdocumentationlackinginanyway,ormissingdocumentationforafeature,
thenthebestthingtodoislearnaboutitandthenwritethedocumentationyourself!
Weacceptpublicdocumentationcontributionsthroughourwikiat:
You’rethebestauthorofthisdocumentation,peoplelikeyouhavetoreadit!
Contents
WhatisMyBatis?
.........................................................................................................................................5
GettingStarted.............................................................................................................................................5
BuildingSqlSessionFactoryfromXML.......................................................................................................5
BuildingSqlSessionFactorywithoutXML..................................................................................................6
AcquiringaSqlSessionfromSqlSessionFactory........................................................................................6
ExploringMappedSQLStatements..........................................................................................................7
ANoteaboutNamespaces....................................................................................................................8
ScopeandLifecycle..................................................................................................................................9
MapperConfigurationXML........................................................................................................................10
properties...............................................................................................................................................11
settings...................................................................................................................................................12
typeAliases.............................................................................................................................................13
typeHandlers..........................................................................................................................................14
objectFactory.........................................................................................................................................15
plugins....................................................................................................................................................16
environments.........................................................................................................................................17
transactionManager............................................................................................................................18
dataSource.........................................................................................................................................19
mappers.................................................................................................................................................21
SQLMapXMLFiles.....................................................................................................................................21
select......................................................................................................................................................22
insert,update,delete..............................................................................................................................24
sql...........................................................................................................................................................26
Parameters.............................................................................................................................................26
MyBatis3-UserGuide
29May20104
resultMap...............................................................................................................................................28
AdvancedResultMapping..................................................................................................................30
id,result.............................................................................................................................................32
SupportedJDBCTypes........................................................................................................................33
constructor.........................................................................................................................................33
association.........................................................................................................................................34
collection............................................................................................................................................37
discriminator......................................................................................................................................40
cache......................................................................................................................................................41
UsingaCustomCache.........................................................................................................................43
cache-ref................................................................................................................................................44
DynamicSQL..............................................................................................................................................44
if.............................................................................................................................................................44
choose,when,otherwise........................................................................................................................45
trim,where,set......................................................................................................................................45
foreach...................................................................................................................................................47
JavaAPI......................................................................................................................................................49
DirectoryStructure................................................................................................................................49
SqlSessions.............................................................................................................................................50
SqlSessionFactoryBuilder....................................................................................................................50
SqlSessionFactory...............................................................................................................................52
SqlSession...........................................................................................................................................54
SelectBuilder..............................................................................................................................................60
SqlBuilder...................................................................................................................................................63
MyBatis3-UserGuide
29May20105
WhatisMyBatis?
MyBatisisafirstclasspersistenceframeworkwithsupportforcustomSQL,storedproceduresand
advancedmappings.MyBatiseliminatesalmostalloftheJDBCcodeandmanualsettingofparameters
andretrievalofresults.MyBatiscanusesimpleXMLorAnnotationsforconfigurationandmap
primitives,MapinterfacesandJavaPOJOs(PlainOldJavaObjects)todatabaserecords.
GettingStarted
EveryMyBatisapplicationcentersaroundaninstanceofSqlSessionFactory.ASqlSessionFactory
instancecanbeacquiredbyusingtheSqlSessionFactoryBuilder.SqlSessionFactoryBuildercanbuilda
SqlSessionFactoryinstancefromanXMLconfigurationfile,offromacustompreparedinstanceofthe
Configurationclass.
BuildingSqlSessionFactoryfromXML
BuildingaSqlSessionFactoryinstancefromanXMLfileisverysimple.Itisrecommendedthatyouusea
classpathresourceforthisconfiguration,butyoucoulduseanyReaderinstance,includingonecreated
fromaliteralfilepathorafile:
//URL.MyBatisincludesautilityclass,calledResources,thatcontainsa
numberofmethodsthatmakeitsimplertoloadresourcesfromtheclasspathandotherlocations.
Stringresource
- 配套讲稿:
如PPT文件的首页显示word图标,表示该PPT已包含配套word讲稿。双击word图标可打开word文档。
- 特殊限制:
部分文档作品中含有的国旗、国徽等图片,仅作为作品整体效果示例展示,禁止商用。设计者仅对作品中独创性部分享有著作权。
- 关 键 词:
- MyBatis3UserGuide