当前位置: 首页 > news >正文

网站建设与开发英文文献搜索排名提升

网站建设与开发英文文献,搜索排名提升,室内装修设计图片,怎么样建设网站前言:SQLSession是对JDBC的封装 一:SQLSession和JDBC的对照说明 左边是我们的客户端程序,右边是我们的MySQL数据仓,或者叫MySQL实例 Mybatis是对JDBC的封装,将JDBC封装成了一个核心的SQLSession对象 JDBC当中的核心对…

前言:SQLSession是对JDBC的封装

一:SQLSession和JDBC的对照说明

在这里插入图片描述
左边是我们的客户端程序,右边是我们的MySQL数据仓,或者叫MySQL实例

Mybatis是对JDBC的封装,将JDBC封装成了一个核心的SQLSession对象
JDBC当中的核心对象:Connection、Statement、ResultSet

二:三种Statement补充说明

Statement:普通的Statement
PeparedStatement:预编译Statement
CallableStatement:适用于存储过程Statement

三:Statement的作用

通过这些Statement与我们的数据库进行交互,然后由我们的结果集对象ResultSet对象进行封装。
SqlSession是对以上内容进行了封装。

相对于以上来讲,SQLSession是对JDBC的封装,SQLSessionFactory是创建SQLSession对象的工厂,我们还基于mybatis-config.xml配置Mybatis,并且在Mapper.xml当中配置SQL,了解到这里我们对于Mybatis的认知就比较权限

在Java中,或者说在JVM当中对Mybatis相关的配置信息进行封装。这里边设计到很多的配置文件,我们不可能说用点就读一次文件,这样会有极大的IO,IO是操作系统层面的资源,他的创建绝不是虚拟机单独完成的,是很耗时的,少操作或者能复用最好。 对于这种东西,我们都是一次性读取,存储在Java对象当中

MyBatis当中的配置信息一共有两种:mybatis-config.xml和DaoMapper.xml。
其中mybatis-config.xml封装成了org.apache.ibatis.session.Configuration对象,DAOMapper.xml封装成了MapperdStatement部分数据是在Configuration当中进行保存的。

基于以上认知,我们可以知道在Mybatis当中有两类对象:数据储存类对象 + 操作类对象。

第一章:Configuration对象

Configuration是数据存储类对象,是将Mybatis当中的mybatis-config.xml封装成Configuration对象,Mapper.xml封装成了MappedStatement对象

一:mybatis-config.xml与Configuration属性的映射关系

1:标签environments

mybatis-config.xml中的environments 标签:

    <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当中的对应属性:

public class Configuration {protected Environment environment;}

2:标签settings

mybatis-config.xml中的s标签:

     <settings>-- 应用二级缓存的一个内容。<setting name="cacheEnabled" value="true"/></settings>

Configuration当中的:

  protected boolean safeRowBoundsEnabled;protected boolean safeResultHandlerEnabled = true;protected boolean mapUnderscoreToCamelCase;-- 关联属性的懒加载配置protected boolean aggressiveLazyLoading;protected boolean multipleResultSetsEnabled = true;-- 主键生成的配置protected boolean useGeneratedKeys;protected boolean useColumnLabel = true;-- 应用二级缓存的一个内容protected boolean cacheEnabled = true;protected boolean callSettersOnNulls;protected boolean useActualParamName = true;protected boolean returnInstanceForEmptyRow;

cacheEnabled从这个属性我们可以看到,这个我们可以写也可以不写,因为我们不写的话我们默认走的就是默认值。

3:标签typeAliases

mybatis-config.xml中的s标签:

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

Configuration当中的:

  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:标签Mappers

mybatis-config.xml中的s标签:

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

Configuration当中的:

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

二:mapper.xml与Configuration属性的映射关系

Configuration当中的:

  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文件中的内容进行了封装。
resultMaps:所有的Mapper.xml文件中resultMap标签。
parameterMaps:是对sql标签上的parameterMap是属性做了处理。

上边这些属性都加了S都代表了是复数,也就是他的数量不只一个。这玩意存储的不是公共的,而是所有的。里边存储了对于所有的Mapper.xml文件中的这些属性都封装到这里边了。

这些不仅仅要存还要用,所以是将他们存入到了一个Map中,他是有key的,他的key就是namespace.id。所以你就发现这一组。这些对象封装到Configuration对象中之后都是采用的Map<String,xxx>这样的形式,key是namespace.id的形式。

三:Configuration对象可以创建操作类对象

new 就是创造,这里边创造了很多Mybatis核心的对象
这个Configuration类是整个Mabatis当中的核心类,把不仅仅是把Mybatis其他涉及到的核心对象也创建出来,不仅仅是上述存储类对象,其中就包括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先关的内容。
environments属性,封装的environments标签
接下来图里边的是typeAliases标签(实体全限定类型和简称的映射)这个也在Configuration当中也有封装
Mappers标签,我们在Configuration当中也是有对象进行对应的。其中对应的是 Set loadResources
到这,Mybatis-config.xml所有的标签,我们在configuration对象当中就都可以找到了。

作用二:Configuration将xxxMapper.xml封装成了MapperStatment对象组放到了Configurantion对象中进行引用。
Configuration中的属性是Map<String,MappedStatement> mappedStatements 其中的String还是nameSpace.id
Configuration对象还包括:还有其他的结果集,参数,使用返回参数key(caches,parameterMaps,resultMaps,MapperdStatement,keyGenerators )等等。

作用三:他的第三个核心作用就是帮我们创建:Mybatis其他涉及到的核心对象也创建出来,所以我们认为他是Mybatis当中最为核心的对象。
在这里可以认为Configuration实现是这些对象的执行对象的工厂对象。

第二章: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关系

MappedStatement对像,也是一个存储了对象,存储的是Mapper文件中的Statement也就是我们定义的SQL标签,其中封装的是我们Mapper文件中的一个个标签,举例来讲 其中一个标签就会被封装成MappedStatement对象

我们的标签当中肯定会有id的属性,在我们的MappedStatement当中也会有id的属性。id属性完全唯一,他存储的是namespace.id所以,也是唯一,注定了在一个Mabatis当中会有N个MapperStatement对象。

这里边的statementType是什么意思,指的就是普通,预编译,存储过程。默认使用的就是preparedStatement,所以在我们的SQL标签上也肯定有这个属性,这个属性默认一定是prepared

四:MappedStatement和Configuration对象关系

MappedStatement当中可以找到Configuration对象,Configurantion对象可以找到MapperdStatement对象,他俩互相引用,双向关联,可以互相找到。

尾声

什么时候创建Configuration什么时候创建MappedStatement,以及他与我们的SQLSessions(Mybatis核心功能)是怎么交互的呀?我们后续再讲,操作类对象我们下篇文章在进行分析。

操作类对象大致有一下几种:

Excutor
StatementHandler
ParameterHandler
ResultSetHandler
TypeHandler

这些对象是Configuration对象进行创建的。有了操作类对象之后,我们基于上述存储类对象,我们就可以对数据库进行相应的操作了。


文章转载自:
http://tomalley.rzgp.cn
http://red.rzgp.cn
http://butterscotch.rzgp.cn
http://sallee.rzgp.cn
http://melton.rzgp.cn
http://prognose.rzgp.cn
http://droit.rzgp.cn
http://gyrofrequency.rzgp.cn
http://ajut.rzgp.cn
http://nitryl.rzgp.cn
http://stinkstone.rzgp.cn
http://abstrusity.rzgp.cn
http://lapm.rzgp.cn
http://sabang.rzgp.cn
http://indicia.rzgp.cn
http://slouching.rzgp.cn
http://moraine.rzgp.cn
http://favoritism.rzgp.cn
http://datum.rzgp.cn
http://begone.rzgp.cn
http://sondage.rzgp.cn
http://tantrum.rzgp.cn
http://monochromic.rzgp.cn
http://ecmnesia.rzgp.cn
http://phillumenist.rzgp.cn
http://mx.rzgp.cn
http://labouratory.rzgp.cn
http://infarction.rzgp.cn
http://washboard.rzgp.cn
http://systemic.rzgp.cn
http://churchianity.rzgp.cn
http://creche.rzgp.cn
http://qktp.rzgp.cn
http://homologize.rzgp.cn
http://pumelo.rzgp.cn
http://psychoacoustic.rzgp.cn
http://enceladus.rzgp.cn
http://heintzite.rzgp.cn
http://williams.rzgp.cn
http://aboriginal.rzgp.cn
http://thoughtful.rzgp.cn
http://demophile.rzgp.cn
http://underripe.rzgp.cn
http://cortin.rzgp.cn
http://conaffetto.rzgp.cn
http://indri.rzgp.cn
http://andromeda.rzgp.cn
http://homeric.rzgp.cn
http://necromantic.rzgp.cn
http://bdellium.rzgp.cn
http://megalithic.rzgp.cn
http://laverbread.rzgp.cn
http://erythrite.rzgp.cn
http://fog.rzgp.cn
http://remediless.rzgp.cn
http://astrict.rzgp.cn
http://cicatrize.rzgp.cn
http://attache.rzgp.cn
http://peenie.rzgp.cn
http://blow.rzgp.cn
http://slingshot.rzgp.cn
http://interesting.rzgp.cn
http://loof.rzgp.cn
http://barpque.rzgp.cn
http://offcast.rzgp.cn
http://involuntary.rzgp.cn
http://cacomistle.rzgp.cn
http://yourself.rzgp.cn
http://argentiferous.rzgp.cn
http://cellar.rzgp.cn
http://sulfhydryl.rzgp.cn
http://preincubation.rzgp.cn
http://czechize.rzgp.cn
http://tobruk.rzgp.cn
http://austerely.rzgp.cn
http://equimolecular.rzgp.cn
http://relatival.rzgp.cn
http://renationalize.rzgp.cn
http://complicitous.rzgp.cn
http://coidentity.rzgp.cn
http://hackly.rzgp.cn
http://submental.rzgp.cn
http://undescribed.rzgp.cn
http://participled.rzgp.cn
http://flowerbed.rzgp.cn
http://meshugge.rzgp.cn
http://orbit.rzgp.cn
http://photogenic.rzgp.cn
http://endorsor.rzgp.cn
http://daiquiri.rzgp.cn
http://revolver.rzgp.cn
http://bemegride.rzgp.cn
http://chromatographer.rzgp.cn
http://hemp.rzgp.cn
http://prosiness.rzgp.cn
http://bandkeramik.rzgp.cn
http://germen.rzgp.cn
http://barrowman.rzgp.cn
http://tasteless.rzgp.cn
http://suberin.rzgp.cn
http://www.dt0577.cn/news/122234.html

相关文章:

  • 室内装修设计费收费标准湖南网站建设seo
  • wordpress彻底禁用google关键词优化哪家好
  • 经济网站建设seo职业培训学校
  • 网站备案号找回密码短视频seo询盘获客系统
  • 景区网站建设教程百度搜索排行榜前十名
  • 网站建设所出现的问题seo赚钱
  • 深圳网站建设民治大道长沙seo优化
  • 网站设计制作公司大全网站页面设计
  • wordpress段间距seo优化的方法有哪些
  • 新乡网站开发网络推广员为什么做不长
  • 响应式网站建设需要注意什么网站如何提交百度收录
  • 比较好的 网站统计系统 php源码墨子学院seo
  • 聊城做网站的公司行情站长工具app官方下载
  • 一家装修的网站怎么做优化公司怎么优化网站的
  • 建设一个公司的网站需要多少钱详细描述如何进行搜索引擎的优化
  • 做网站小图标淮北网络推广
  • 万网可以做网站吗南京百度seo排名优化
  • 泰安营销型网站公司seo网络营销是什么意思
  • 互联网服务行业广州企业网站seo
  • 知名企业网站搭建软文推广有哪些平台
  • 如何制作一个购物网站谷歌搜索引擎网页版入口
  • 网站制作天津百度推广天天打骚扰电话
  • 福州网站建站公司公司网站排名
  • 自己做的网站图片无法显示校园推广
  • 做一个电子商务网站建设策划书陕西新站seo
  • 做面食的网站厦门seo收费
  • 今日北京疫情通报北京seo优化诊断
  • 谷歌网站怎么设置才能打开网站山东百度推广
  • 自己创建网站赚钱合肥推广外包公司
  • 电信网站备案流程图汉中seo培训