您好,欢迎访问三七文档
当前位置:首页 > 商业/管理/HR > 经营企划 > 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
本文标题:mybatis-3.2.0官方文档
链接地址:https://www.777doc.com/doc-5970334 .html