MyBatis3UserGuide.docx

上传人:b****5 文档编号:12566463 上传时间:2023-04-20 格式:DOCX 页数:122 大小:63.24KB
下载 相关 举报
MyBatis3UserGuide.docx_第1页
第1页 / 共122页
MyBatis3UserGuide.docx_第2页
第2页 / 共122页
MyBatis3UserGuide.docx_第3页
第3页 / 共122页
MyBatis3UserGuide.docx_第4页
第4页 / 共122页
MyBatis3UserGuide.docx_第5页
第5页 / 共122页
点击查看更多>>
下载资源
资源描述

MyBatis3UserGuide.docx

《MyBatis3UserGuide.docx》由会员分享,可在线阅读,更多相关《MyBatis3UserGuide.docx(122页珍藏版)》请在冰豆网上搜索。

MyBatis3UserGuide.docx

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

展开阅读全文
相关资源
猜你喜欢
相关搜索

当前位置:首页 > 高等教育 > 其它

copyright@ 2008-2022 冰豆网网站版权所有

经营许可证编号:鄂ICP备2022015515号-1