mybatis-3.2.0官方文档

整理文档很辛苦,赏杯茶钱您下走!

免费阅读已结束,点击下载阅读编辑剩下 ...

阅读已结束,您可以下载文档离线阅读编辑

资源描述

......................................................................................................................................MyBatisv.3.2.0UserGuide......................................................................................................................................MyBatis.org2013-02-20TableofContentsi©2013,MyBatis.org•ALLRIGHTSRESERVED.TableofContents.......................................................................................................................................1.TableofContents...........................................................i2.Introduction.................................................................13.GettingStarted..............................................................24.ConfigurationXML..........................................................75.MapperXMLFiles..........................................................246.DynamicSQL..............................................................527.JavaAPI....................................................................588.StatementBuilders........................................................749.Logging.....................................................................80TableofContentsii©2013,MyBatis.org•ALLRIGHTSRESERVED.1Introduction1©2013,MyBatis.org•ALLRIGHTSRESERVED.1Introduction.......................................................................................................................................1.1Introduction1.1.1WhatisMyBatis?MyBatisisafirstclasspersistenceframeworkwithsupportforcustomSQL,storedproceduresandadvancedmappings.MyBatiseliminatesalmostalloftheJDBCcodeandmanualsettingofparametersandretrievalofresults.MyBatiscanusesimpleXMLorAnnotationsforconfigurationandmapprimitives,MapinterfacesandJavaPOJOs(PlainOldJavaObjects)todatabaserecords.1.1.2Helpmakethisdocumentationbetter…Ifyoufindthisdocumentationlackinginanyway,ormissingdocumentationforafeature,thenthebestthingtodoislearnaboutitandthenwritethedocumentationyourself!Sourcesofthismanualareavailableinxdocformatatproject'sGit.Checkthemout,updatethemandsendyourpatchtothetracker.You’rethebestauthorofthisdocumentation,peoplelikeyouhavetoreadit!1.1.3TranslationsUserscanreadaboutMyBatisinfollowingtranslations:•English•Español•###•###•####DoyouwanttoreadaboutMyBatisinyourownnativelanguage?Fillanissueprovidingpatcheswithyourmothertonguedocumentation!2GettingStarted2©2013,MyBatis.org•ALLRIGHTSRESERVED.2GettingStarted.......................................................................................................................................2.1GettingstartedEveryMyBatisapplicationcentersaroundaninstanceofSqlSessionFactory.ASqlSessionFactoryinstancecanbeacquiredbyusingtheSqlSessionFactoryBuilder.SqlSessionFactoryBuildercanbuildaSqlSessionFactoryinstancefromanXMLconfigurationfile,offromacustompreparedinstanceoftheConfigurationclass.2.1.1BuildingSqlSessionFactoryfromXMLBuildingaSqlSessionFactoryinstancefromanXMLfileisverysimple.Itisrecommendedthatyouuseaclasspathresourceforthisconfiguration,butyoucoulduseanyInputStreaminstance,includingonecreatedfromaliteralfilepathorafile://URL.MyBatisincludesautilityclass,calledResources,thatcontainsanumberofmethodsthatmakeitsimplertoloadresourcesfromtheclasspathandotherlocations.Stringresource=org/mybatis/example/mybatis-config.xml;InputStreaminputStream=Resources.getResourceAsStream(resource);sqlSessionFactory=newSqlSessionFactoryBuilder().build(inputStream);TheconfigurationXMLfilecontainssettingsforthecoreoftheMyBatissystem,includingaDataSourceforacquiringdatabaseConnectioninstances,aswellasaTransactionManagerfordetermininghowtransactionsshouldbescopedandcontrolled.ThefulldetailsoftheXMLconfigurationfilecanbefoundlaterinthisdocument,buthereisasimpleexample:?xmlversion=1.0encoding=UTF-8?!DOCTYPEconfigurationPUBLIC-//mybatis.org//DTDConfig3.0//EN=developmentenvironmentid=developmenttransactionManagertype=JDBC/dataSourcetype=POOLEDpropertyname=drivervalue=${driver}/propertyname=urlvalue=${url}/propertyname=usernamevalue=${username}/propertyname=passwordvalue=${password}//dataSource/environment/environmentsmappersmapperresource=org/mybatis/example/BlogMapper.xml//mappers/configurationWhilethereisalotmoretotheXMLconfigurationfile,theaboveexamplepointsoutthemostcriticalparts.NoticetheXMLheader,requiredtovalidatetheXMLdocument.Thebodyoftheenvironmentelementcontainstheenvironmentconfigurationfortransactionmanagementandconnectionpooling.2GettingStarted3©2013,MyBatis.org•ALLRIGHTSRESERVED.Themapperselementcontainsalistofmappers–theXMLfilesthatcontaintheSQLcodeandmappingdefinitions.2.1.2BuildingSqlSessionFactorywithoutXMLIfyouprefertodirectlybuildtheconfigurationfromJava,ratherthanXML,orcreateyourownconfigurationbuilder,MyBatisprovidesacompleteConfigurationclassthatprovidesallofthesameconfigurationoptionsastheXMLfile.DataSourcedataSource=BlogDataSourceFactory.getBlogDataSo

1 / 86
下载文档,编辑使用

©2015-2020 m.777doc.com 三七文档.

备案号:鲁ICP备2024069028号-1 客服联系 QQ:2149211541

×
保存成功