第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號(hào)安全,請(qǐng)及時(shí)綁定郵箱和手機(jī)立即綁定

mybatis一級(jí)緩存的問(wèn)題

spring整合mybatis后,sqlSeesion被sprinhIoc容器管理起來(lái)。假如第一次查詢數(shù)據(jù)庫(kù)用到sqlSeesion1,第二次我還是進(jìn)行相同的查詢操作,Ioc容器會(huì)使用上次給我的sqlSession1(也就是使用緩存),還是會(huì)重新創(chuàng)建一個(gè)新的sqlSession。

正在回答

2 回答

關(guān)于緩存問(wèn)題:

http://www.cnblogs.com/zemliu/archive/2013/08/05/3239014.html

執(zhí)行了2次sql查詢,看似我們使用了同一個(gè)sqlSession,但是實(shí)際上因?yàn)槲覀兊膁ao繼承了SqlSessionDaoSupport,而SqlSessionDaoSupport內(nèi)部sqlSession的實(shí)現(xiàn)是使用用動(dòng)態(tài)代理實(shí)現(xiàn)的,這個(gè)動(dòng)態(tài)代理sqlSessionProxy使用一個(gè)模板方法封裝了select()等操作,每一次select()查詢都會(huì)自動(dòng)先執(zhí)行openSession(),執(zhí)行完close()以后調(diào)用close()方法,相當(dāng)于生成了一個(gè)新的session實(shí)例,所以我們無(wú)需手動(dòng)的去關(guān)閉這個(gè)session()(關(guān)于這一點(diǎn)見(jiàn)下面mybatis的官方文檔),當(dāng)然也無(wú)法使用mybatis的一級(jí)緩存,也就是說(shuō)mybatis的一級(jí)緩存在spring中是沒(méi)有作用的.

官方文檔摘要

MyBatis?SqlSession?provides you with specific methods to handle transactions programmatically. But when using MyBatis-Spring your beans will be injected with a Spring managed?SqlSession?or a Spring managed mapper. That means that Spring will?always?handle your transactions.

You cannot call?SqlSession.commit(),?SqlSession.rollback()?or?SqlSession.close()?over a Spring managed?SqlSession. If you try to do so, a?UnsupportedOperationException?exception will be thrown. Note these methods are not exposed in injected mapper classes.


0 回復(fù) 有任何疑惑可以回復(fù)我~

會(huì)重新創(chuàng)建一個(gè)新的sqlSession,因?yàn)槊看蔚臄?shù)據(jù)庫(kù)操作,一般都是以下四步:

1,獲取SqlSession對(duì)象

2,調(diào)用數(shù)據(jù)庫(kù)操作的方法

3,提交事務(wù)

4,關(guān)閉SqlSession

0 回復(fù) 有任何疑惑可以回復(fù)我~
#1

朱小懸 提問(wèn)者

查詢操作不需要提交事務(wù)吧?
2017-05-09 回復(fù) 有任何疑惑可以回復(fù)我~

舉報(bào)

0/150
提交
取消

mybatis一級(jí)緩存的問(wèn)題

我要回答 關(guān)注問(wèn)題
微信客服

購(gòu)課補(bǔ)貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動(dòng)學(xué)習(xí)伙伴

公眾號(hào)

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號(hào)