小編給大家分享一下iBATIS SQLMap如何配置,相信大部分人都還不怎么了解,因此分享這篇文章給大家參考一下,希望大家閱讀完這篇文章后大有收獲,下面讓我們一起去了解一下吧!
成都創(chuàng)新互聯(lián)公司主要業(yè)務(wù)有網(wǎng)站營銷策劃、成都網(wǎng)站設(shè)計、做網(wǎng)站、微信公眾號開發(fā)、小程序開發(fā)、H5建站、程序開發(fā)等業(yè)務(wù)。一次合作終身朋友,是我們奉行的宗旨;我們不僅僅把客戶當(dāng)客戶,還把客戶視為我們的合作伙伴,在開展業(yè)務(wù)的過程中,公司還積累了豐富的行業(yè)經(jīng)驗、成都全網(wǎng)營銷推廣資源和合作伙伴關(guān)系資源,并逐漸建立起規(guī)范的客戶服務(wù)和保障體系。
iBATIS的SQLMap配置文件是XML形式,一般叫SqlMapConfig.xml,如下:
Xml代碼
﹤?xml version="1.0" encoding="UTF-8"?﹥ ﹤!DOCTYPE sqlMapConfig PUBLIC "-//iBATIS.com//DTD SQL Map Config 2.0/" "http://www.ibatis.com/dtd/sql-map-config-2.dtd"﹥ ﹤sqlMapConfig﹥ ﹤!--settings配置是可選的,用來控制sqlMapping的詳細配置,主要是事務(wù)處理。參數(shù)具體含義請參考ibatis開發(fā)指南--﹥ ﹤settings cacheModelsEnabled="true" enhancementEnabled="true" lazyLoadingEnabled="true" errorTracingEnabled="true" maxRequests="32" maxSessions="10" maxTransactions="5" useStatementNamespaces="false" /﹥ ﹤!--使用SimpleDataSource配置數(shù)據(jù)源,DataSource的iBATIS實現(xiàn):SimpleDataSource類,Jakarta DBCP(Commons),和可通過JNDI上下文查找的DataSource(即應(yīng)用接下來是iBATIS SQLMap映射文件Account.xml:
Xml代碼
﹤?xml version="1.0" encoding="UTF-8"?﹥ ﹤!DOCTYPE sqlMap PUBLIC "-//iBATIS.com//DTD SQL Map 2.0//EN" "http://www.ibatis.com/dtd/sql-map-2.dtd"﹥ ﹤sqlMap namespace="Account"﹥ ﹤!--在SQL Map框架中,Result Map是極其重要的組件。在執(zhí)行查詢Mapped Statement時,resultMap負責(zé)將結(jié)果集的列值映射成Java Bean的屬性值。--﹥ ﹤resultMap id="result" class="org.springframework.samples.jpetstore.domain.Account"﹥ ﹤result property="username" column="userid" columnIndex="1" /﹥ ﹤result property="email" column="email" columnIndex="2" /﹥ ﹤result property="firstName" column="firstname" columnIndex="3" /﹥ ﹤result property="lastName" column="lastname" columnIndex="4" /﹥ ﹤result property="status" column="status" columnIndex="5" /﹥ ﹤result property="address1" column="addr1" columnIndex="6" /﹥ ﹤result property="address2" column="addr2" columnIndex="7" /﹥ ﹤result property="city" column="city" columnIndex="8" /﹥ ﹤result property="state" column="state" columnIndex="9" /﹥ ﹤result property="zip" column="zip" columnIndex="10" /﹥ ﹤result property="country" column="country" columnIndex="11" /﹥ ﹤result property="phone" column="phone" columnIndex="12" /﹥﹤/resultMap﹥ ﹤select id="getAllAccountByUserid" resultMap="result"﹥ select account.userid, account.email, account.firstname, account.lastname, account.status, account.addr1, account.addr2, account.city, account.state, account.zip, account.country, account.phone from account where account.userid=#value# ﹤/select﹥ ﹤/sqlMap﹥下面是iBATIS SQLMap的Java代碼:
Java代碼
try { String resource = "com/quqworld/test/ibatis/SqlMapConfig.xml"; Reader reader = Resources.getResourceAsReader(resource); SqlMapClient sqlMap = SqlMapClientBuilder.buildSqlMapClient(reader); Object object = sqlMap.queryForObject( "getAllAccountByUserid", "ACID",new Account()); System.out.println("select result: " +object); } catch (Exception e) { e.printStackTrace(); }iBATIS SQLMap的配置Demo就向你介紹到這里,希望對你有所幫助。
以上是“iBATIS SQLMap如何配置”這篇文章的所有內(nèi)容,感謝各位的閱讀!相信大家都有了一定的了解,希望分享的內(nèi)容對大家有所幫助,如果還想學(xué)習(xí)更多知識,歡迎關(guān)注創(chuàng)新互聯(lián)行業(yè)資訊頻道!
網(wǎng)頁標題:iBATISSQLMap如何配置
網(wǎng)站地址:http://weahome.cn/article/igijpi.html