ibatis載入關聯關係的兩種方法

2021-05-22 23:32:16 字數 797 閱讀 9770

ibatis有兩種載入關聯關係的方法:

1. nested select:select另乙個載入資料的sql語句id

select * from blog where id = #

select * from author where id = #

在這裡我們有兩個select語句,乙個去載入blog資料,另乙個去載入author資料,在blog定義的resultmap中使用了載入

author的select語句,對blog中的author屬性進行賦值。也就是說,這種簡單的一對一關係,執行了兩條select語句。

使用nested select會產生「n+1」問題,非常常見,效能消耗相當大,可以使用懶載入來解決,或者使用下面一種方法。

2.nested result:對映關聯屬性欄位的resultmap id值,採用join的方式一次查詢得出結果

或者:在select語句中使用:

select

b.id as blog_id, b.title as blog_title, b.author_id as blog_author_id,

a.id as author_id, a.username as author_username, a.password as

author_password, a.email as author_email, a.bio as author_bio from

blog b left outer join author a on b.author_id = a.id where b.id =

#

UIWebView載入Loading 兩種方法

from 第一種方法 使用uiview and uiactivityindicatorview 建立uiwebview webview uiwebview alloc initwithframe cgrectmake 0 44 320 400 webview setuserinteractionen...

UIWebView載入Loading 兩種方法

uiwebview載入loading.兩種方法 第一種方法 使用uiview and uiactivityindicatorview 建立uiwebview webview uiwebview alloc initwithframe cgrectmake 0,44,320,400 webview s...

UIWebView載入Loading 兩種方法

第一種方法 使用uiview and uiactivityindicatorview 建立uiwebview webview uiwebview alloc initwithframe cgrectmake 0,44,320,400 webview setuserinteractionenabled...