Mybatis 原始碼分析

2021-08-04 11:48:18 字數 1545 閱讀 7957

mybatis解析:

2、 sqlsessionfactorybean 繼承了 initializingbean 介面,在bean解析的finishbeanfactoryinitialization() 的方法對 initializingbean介面中的 afterpropertiesset()方法進行呼叫,初始化mybatis的sqlsessionfactory例項,包括以下動作:

1)、解析configlocation屬性,其中能包括 typealiases,typehandlers 等的解析

2)、解析datasource屬性

}try catch (exception e) }}

public t newinstance(sqlsession sqlsession)

public object invoke(object proxy, method method, object args) throws throwable catch (throwable t) }}

// method 為methodsignature,通過此類能解析出本方法要返回的型別等}}

4、mybatis 比較兩個欄位名是否相同通過將兩個欄位名統一轉換成大寫後比較是否一致

5、mybatis ioc實現:

final resultloadermap lazyloader = new resultloadermap();

object resultobject = createresultobject(rsw, resultmap, lazyloader, null);

if (resultobject != null && !typehandlerregistry.hastypehandler(resultmap.gettype()))

foundvalues = lazyloader.size() > 0 || foundvalues;

resultobject = foundvalues ? resultobject : null;

return resultobject;

}return resultobject;

}boolean foundvalues = false;

string propertyname = columnname;

if (columnprefix != null && !columnprefix.isempty()) else

}final string property = metaobject.findproperty(propertyname, configuration.ismapunderscoretocamelcase());

if (property != null && metaobject.hassetter(property))

foundvalues = true;}}

}}return foundvalues;

}6、resulthandler 用於處理返回的結果集,使用方法: void getuser(integer id,userresulthandler resulthandler)。注意方法的返回值一定得為 void 才能生效。

Mybatis原始碼分析

我們都知道mybatis它是一款優秀的持久層框架,它支援定製化sql 儲存過程以及高階對映,幫我們節省了許多時間與精力,今天我們主要來對mybatis的底層原始碼進行分析,主要是以下4行 首先呼叫resources中的單個string引數的getresuorceasstream string res...

MyBatis 原始碼分析

sqlsession inte ce,代表乙個連線資料庫的會話,提供了乙個預設的 defaultsqlsession sqlsessionfactory inte ct,建立 sqlsessionfactory 的工廠,提供了預設的 defaultsqlsessionfactory建立 defaul...

MyBatis原始碼分析

將mybatis config.xml加載入inputstream中。呼叫sqlsessionfactotybuilder build 方法,將流傳入其中。sqlsessionfactotybuilder build 方法中有乙個xmlconfigbuilder類解析xml中的內容,封裝為乙個con...