中文亚洲精品无码_熟女乱子伦免费_人人超碰人人爱国产_亚洲熟妇女综合网

當(dāng)前位置: 首頁 > news >正文

龍崗沙灣社區(qū)網(wǎng)站建設(shè)邵陽網(wǎng)站seo

龍崗沙灣社區(qū)網(wǎng)站建設(shè),邵陽網(wǎng)站seo,寧波seo,哪些網(wǎng)站可以做go注釋前言:SQLSession是對JDBC的封裝 一:SQLSession和JDBC的對照說明 左邊是我們的客戶端程序,右邊是我們的MySQL數(shù)據(jù)倉,或者叫MySQL實例 Mybatis是對JDBC的封裝,將JDBC封裝成了一個核心的SQLSession對象 JDBC當(dāng)中的核心對…

前言:SQLSession是對JDBC的封裝

一:SQLSession和JDBC的對照說明

在這里插入圖片描述
左邊是我們的客戶端程序,右邊是我們的MySQL數(shù)據(jù)倉,或者叫MySQL實例

Mybatis是對JDBC的封裝,將JDBC封裝成了一個核心的SQLSession對象
JDBC當(dāng)中的核心對象:Connection、Statement、ResultSet

二:三種Statement補充說明

Statement:普通的Statement
PeparedStatement:預(yù)編譯Statement
CallableStatement:適用于存儲過程Statement

三:Statement的作用

通過這些Statement與我們的數(shù)據(jù)庫進(jìn)行交互,然后由我們的結(jié)果集對象ResultSet對象進(jìn)行封裝。
SqlSession是對以上內(nèi)容進(jìn)行了封裝。

相對于以上來講,SQLSession是對JDBC的封裝,SQLSessionFactory是創(chuàng)建SQLSession對象的工廠,我們還基于mybatis-config.xml配置Mybatis,并且在Mapper.xml當(dāng)中配置SQL,了解到這里我們對于Mybatis的認(rèn)知就比較權(quán)限

在Java中,或者說在JVM當(dāng)中對Mybatis相關(guān)的配置信息進(jìn)行封裝。這里邊設(shè)計到很多的配置文件,我們不可能說用點就讀一次文件,這樣會有極大的IO,IO是操作系統(tǒng)層面的資源,他的創(chuàng)建絕不是虛擬機(jī)單獨完成的,是很耗時的,少操作或者能復(fù)用最好。 對于這種東西,我們都是一次性讀取,存儲在Java對象當(dāng)中

MyBatis當(dāng)中的配置信息一共有兩種:mybatis-config.xml和DaoMapper.xml。
其中mybatis-config.xml封裝成了org.apache.ibatis.session.Configuration對象,DAOMapper.xml封裝成了MapperdStatement部分?jǐn)?shù)據(jù)是在Configuration當(dāng)中進(jìn)行保存的。

基于以上認(rèn)知,我們可以知道在Mybatis當(dāng)中有兩類對象:數(shù)據(jù)儲存類對象 + 操作類對象。

第一章:Configuration對象

Configuration是數(shù)據(jù)存儲類對象,是將Mybatis當(dāng)中的mybatis-config.xml封裝成Configuration對象,Mapper.xml封裝成了MappedStatement對象

一:mybatis-config.xml與Configuration屬性的映射關(guān)系

1:標(biāo)簽environments

mybatis-config.xml中的environments 標(biāo)簽:

    <environments default="default"><environment id="default"><transactionManager type="JDBC"></transactionManager><dataSource type="POOLED"><property name="driver" value="com.mysql.jdbc.Driver"></property><property name="url" value="jdbc:mysql://localhost:3306/suns?useSSL=false"></property><property name="username" value="root"></property><property name="password" value="123456"></property></dataSource></environment></environments>

Configuration當(dāng)中的對應(yīng)屬性:

public class Configuration {protected Environment environment;}

2:標(biāo)簽settings

mybatis-config.xml中的s標(biāo)簽:

     <settings>-- 應(yīng)用二級緩存的一個內(nèi)容。<setting name="cacheEnabled" value="true"/></settings>

Configuration當(dāng)中的:

  protected boolean safeRowBoundsEnabled;protected boolean safeResultHandlerEnabled = true;protected boolean mapUnderscoreToCamelCase;-- 關(guān)聯(lián)屬性的懶加載配置protected boolean aggressiveLazyLoading;protected boolean multipleResultSetsEnabled = true;-- 主鍵生成的配置protected boolean useGeneratedKeys;protected boolean useColumnLabel = true;-- 應(yīng)用二級緩存的一個內(nèi)容protected boolean cacheEnabled = true;protected boolean callSettersOnNulls;protected boolean useActualParamName = true;protected boolean returnInstanceForEmptyRow;

cacheEnabled從這個屬性我們可以看到,這個我們可以寫也可以不寫,因為我們不寫的話我們默認(rèn)走的就是默認(rèn)值。

3:標(biāo)簽typeAliases

mybatis-config.xml中的s標(biāo)簽:

<typeAliases><typeAlias type="com.baizhiedu.entity.User" alias="User"/><typeAlias type="com.baizhiedu.entity.Account" alias="Account"/>
</typeAliases>

Configuration當(dāng)中的:

  protected final MapperRegistry mapperRegistry = new MapperRegistry(this);protected final InterceptorChain interceptorChain = new InterceptorChain();protected final TypeHandlerRegistry typeHandlerRegistry = new TypeHandlerRegistry();protected final TypeAliasRegistry typeAliasRegistry = new TypeAliasRegistry();protected final LanguageDriverRegistry languageRegistry = new LanguageDriverRegistry();

4:標(biāo)簽Mappers

mybatis-config.xml中的s標(biāo)簽:

    <mappers><!--<package name=""--><mapper resource="UserDAOMapper.xml"/><mapper resource="AccountDAOMapper.xml"/></mappers>

Configuration當(dāng)中的:

protected final Set<String> loadedResources = new HashSet<String>();

二:mapper.xml與Configuration屬性的映射關(guān)系

Configuration當(dāng)中的:

  protected final Map<String, MappedStatement> mappedStatements = new StrictMap<MappedStatement>("Mapped Statements collection");protected final Map<String, Cache> caches = new StrictMap<Cache>("Caches collection");protected final Map<String, ResultMap> resultMaps = new StrictMap<ResultMap>("Result Maps collection");protected final Map<String, ParameterMap> parameterMaps = new StrictMap<ParameterMap>("Parameter Maps collection");protected final Map<String, KeyGenerator> keyGenerators = new StrictMap<KeyGenerator>("Key Generators collection");

caches,parameterMaps,resultMaps,MapperdStatement,keyGenerators 這些是把Mapper.xml文件中的內(nèi)容進(jìn)行了封裝。
resultMaps:所有的Mapper.xml文件中resultMap標(biāo)簽。
parameterMaps:是對sql標(biāo)簽上的parameterMap是屬性做了處理。

上邊這些屬性都加了S都代表了是復(fù)數(shù),也就是他的數(shù)量不只一個。這玩意存儲的不是公共的,而是所有的。里邊存儲了對于所有的Mapper.xml文件中的這些屬性都封裝到這里邊了。

這些不僅僅要存還要用,所以是將他們存入到了一個Map中,他是有key的,他的key就是namespace.id。所以你就發(fā)現(xiàn)這一組。這些對象封裝到Configuration對象中之后都是采用的Map<String,xxx>這樣的形式,key是namespace.id的形式。

三:Configuration對象可以創(chuàng)建操作類對象

new 就是創(chuàng)造,這里邊創(chuàng)造了很多Mybatis核心的對象
這個Configuration類是整個Mabatis當(dāng)中的核心類,把不僅僅是把Mybatis其他涉及到的核心對象也創(chuàng)建出來,不僅僅是上述存儲類對象,其中就包括Excuter,StatementHanler,ResultHandler,ParamerHandler

public ParameterHandler newParameterHandler(MappedStatement mappedStatement, Object parameterObject, BoundSql boundSql) {ParameterHandler parameterHandler = mappedStatement.getLang().createParameterHandler(mappedStatement, parameterObject, boundSql);parameterHandler = (ParameterHandler) interceptorChain.pluginAll(parameterHandler);return parameterHandler;}public ResultSetHandler newResultSetHandler(Executor executor, MappedStatement mappedStatement, RowBounds rowBounds, ParameterHandler parameterHandler,ResultHandler resultHandler, BoundSql boundSql) {ResultSetHandler resultSetHandler = new DefaultResultSetHandler(executor, mappedStatement, parameterHandler, resultHandler, boundSql, rowBounds);resultSetHandler = (ResultSetHandler) interceptorChain.pluginAll(resultSetHandler);return resultSetHandler;}public StatementHandler newStatementHandler(Executor executor, MappedStatement mappedStatement, Object parameterObject, RowBounds rowBounds, ResultHandler resultHandler, BoundSql boundSql) {StatementHandler statementHandler = new RoutingStatementHandler(executor, mappedStatement, parameterObject, rowBounds, resultHandler, boundSql);statementHandler = (StatementHandler) interceptorChain.pluginAll(statementHandler);return statementHandler;}public Executor newExecutor(Transaction transaction) {return newExecutor(transaction, defaultExecutorType);}public Executor newExecutor(Transaction transaction, ExecutorType executorType) {executorType = executorType == null ? defaultExecutorType : executorType;executorType = executorType == null ? ExecutorType.SIMPLE : executorType;Executor executor;if (ExecutorType.BATCH == executorType) {executor = new BatchExecutor(this, transaction);} else if (ExecutorType.REUSE == executorType) {executor = new ReuseExecutor(this, transaction);} else {executor = new SimpleExecutor(this, transaction);}if (cacheEnabled) {executor = new CachingExecutor(executor);}executor = (Executor) interceptorChain.pluginAll(executor);return executor;}

四:Configuration對象的作用

作用一:封裝Mybatis-Config.xml先關(guān)的內(nèi)容。
environments屬性,封裝的environments標(biāo)簽
接下來圖里邊的是typeAliases標(biāo)簽(實體全限定類型和簡稱的映射)這個也在Configuration當(dāng)中也有封裝
Mappers標(biāo)簽,我們在Configuration當(dāng)中也是有對象進(jìn)行對應(yīng)的。其中對應(yīng)的是 Set loadResources
到這,Mybatis-config.xml所有的標(biāo)簽,我們在configuration對象當(dāng)中就都可以找到了。

作用二:Configuration將xxxMapper.xml封裝成了MapperStatment對象組放到了Configurantion對象中進(jìn)行引用。
Configuration中的屬性是Map<String,MappedStatement> mappedStatements 其中的String還是nameSpace.id
Configuration對象還包括:還有其他的結(jié)果集,參數(shù),使用返回參數(shù)key(caches,parameterMaps,resultMaps,MapperdStatement,keyGenerators )等等。

作用三:他的第三個核心作用就是幫我們創(chuàng)建:Mybatis其他涉及到的核心對象也創(chuàng)建出來,所以我們認(rèn)為他是Mybatis當(dāng)中最為核心的對象。
在這里可以認(rèn)為Configuration實現(xiàn)是這些對象的執(zhí)行對象的工廠對象。

第二章:MappedStatement對象

一:MappedStatement屬性

public final class MappedStatement {private String resource;private Configuration configuration;private String id;private Integer fetchSize;private Integer timeout;private StatementType statementType;private ResultSetType resultSetType;private SqlSource sqlSource;private Cache cache;private ParameterMap parameterMap;private List<ResultMap> resultMaps;private boolean flushCacheRequired;private boolean useCache;private boolean resultOrdered;private SqlCommandType sqlCommandType;private KeyGenerator keyGenerator;private String[] keyProperties;private String[] keyColumns;private boolean hasNestedResultMaps;private String databaseId;private Log statementLog;private LanguageDriver lang;private String[] resultSets;}

二:MappedStatement和Mapper.xml關(guān)系

MappedStatement對像,也是一個存儲了對象,存儲的是Mapper文件中的Statement也就是我們定義的SQL標(biāo)簽,其中封裝的是我們Mapper文件中的一個個標(biāo)簽,舉例來講 其中一個標(biāo)簽就會被封裝成MappedStatement對象

我們的標(biāo)簽當(dāng)中肯定會有id的屬性,在我們的MappedStatement當(dāng)中也會有id的屬性。id屬性完全唯一,他存儲的是namespace.id所以,也是唯一,注定了在一個Mabatis當(dāng)中會有N個MapperStatement對象。

這里邊的statementType是什么意思,指的就是普通,預(yù)編譯,存儲過程。默認(rèn)使用的就是preparedStatement,所以在我們的SQL標(biāo)簽上也肯定有這個屬性,這個屬性默認(rèn)一定是prepared

四:MappedStatement和Configuration對象關(guān)系

MappedStatement當(dāng)中可以找到Configuration對象,Configurantion對象可以找到MapperdStatement對象,他倆互相引用,雙向關(guān)聯(lián),可以互相找到。

尾聲

什么時候創(chuàng)建Configuration什么時候創(chuàng)建MappedStatement,以及他與我們的SQLSessions(Mybatis核心功能)是怎么交互的呀?我們后續(xù)再講,操作類對象我們下篇文章在進(jìn)行分析。

操作類對象大致有一下幾種:

Excutor
StatementHandler
ParameterHandler
ResultSetHandler
TypeHandler

這些對象是Configuration對象進(jìn)行創(chuàng)建的。有了操作類對象之后,我們基于上述存儲類對象,我們就可以對數(shù)據(jù)庫進(jìn)行相應(yīng)的操作了。

http://m.risenshineclean.com/news/64529.html

相關(guān)文章:

  • 浦東企業(yè)網(wǎng)站建設(shè)網(wǎng)盟推廣是什么意思
  • 做網(wǎng)站基本教程關(guān)鍵詞推廣seo
  • 重慶做網(wǎng)站有哪些seo泛目錄培訓(xùn)
  • 網(wǎng)站后臺管理頁面模板國際新聞網(wǎng)站
  • 1建設(shè)網(wǎng)站的重要性win7優(yōu)化工具
  • 怎樣做自己的小說網(wǎng)站外貿(mào)營銷型網(wǎng)站建設(shè)公司
  • 全面的網(wǎng)站建設(shè)免費sem工具
  • 慈善系統(tǒng)網(wǎng)站建設(shè)需求網(wǎng)站建設(shè)教程
  • 快速學(xué)制作網(wǎng)站百度小說排行榜第一名
  • wordpress 導(dǎo)航站模板營銷型網(wǎng)站建設(shè)論文
  • 布偶貓網(wǎng)頁設(shè)計教程百度seo入駐
  • 注冊網(wǎng)站頁面跳轉(zhuǎn)錯誤惠州seo排名優(yōu)化
  • 手機(jī)網(wǎng)站Com全國十大婚戀網(wǎng)站排名
  • 怎樣建立手機(jī)網(wǎng)站廣告營銷策略有哪些
  • 有自己域名如何做網(wǎng)站色盲測試圖第六版及答案大全
  • 微信上瀏覽自己做的網(wǎng)站免費下載app并安裝
  • 做阿里還是網(wǎng)站濰坊百度關(guān)鍵詞優(yōu)化
  • 微商網(wǎng)站制作武漢關(guān)鍵詞排名推廣
  • 哪些網(wǎng)站可以找到做海報的素材鄭州seo網(wǎng)站排名
  • xxx網(wǎng)站策劃書西安網(wǎng)頁設(shè)計
  • 莫名接到網(wǎng)站建設(shè)電話推廣引流工具
  • 溫嶺做網(wǎng)站新冠疫情最新消息今天
  • 營銷型網(wǎng)站建設(shè)實戰(zhàn)》杭州優(yōu)化公司哪家好
  • 中國建設(shè)銀行的業(yè)務(wù)范圍深圳百度網(wǎng)站排名優(yōu)化
  • 日照疫情最新消息今天封城了廣州網(wǎng)絡(luò)seo公司
  • 個人網(wǎng)站備案 淘寶客天氣預(yù)報最新天氣預(yù)報
  • 心理咨詢網(wǎng)站開發(fā)長春網(wǎng)站建設(shè)制作
  • 坪山做網(wǎng)站的公司北京全網(wǎng)營銷推廣
  • 網(wǎng)站建設(shè)分幾模塊黃頁推廣引流網(wǎng)站
  • 哪些網(wǎng)站可以做調(diào)查賺錢優(yōu)化推廣網(wǎng)站seo