MyBatis原理分析(通俗易懂)

article/2025/9/1 12:57:00

MyBatis原理分析

  • MyBatis工作流程简述
  • 原生MyBatis原理分析
    • 初始化工作
      • 解析配置文件
      • 配置类方式
    • 执行SQL
      • SqlSession API方式
      • 接口方式

真正掌握一个框架源码分析是少不了的~

在讲解整合Spring的原理之前理解原生的MyBatis执行原理是非常有必要的

MyBatis工作流程简述

传统工作模式:

public static void main(String[] args) {InputStream inputStream = Resources.getResourceAsStream("mybatis-config.xml");SqlSessionFactory factory = new SqlSessionFactoryBuilder().build(inputStream);SqlSession sqlSession = factory.openSession();String name = "tom";List<User> list = sqlSession.selectList("com.demo.mapper.UserMapper.getUserByName",params);
}
  1. 创建SqlSessionFactoryBuilder对象,调用build(inputstream)方法读取并解析配置文件,返回SqlSessionFactory对象
  2. 由SqlSessionFactory创建SqlSession 对象,没有手动设置的话事务默认开启
  3. 调用SqlSession中的api,传入Statement Id和参数,内部进行复杂的处理,最后调用jdbc执行SQL语句,封装结果返回。

使用Mapper接口:
由于面向接口编程的趋势,MyBatis也实现了通过接口调用mapper配置文件中的SQL语句

public static void main(String[] args) {//前三步都相同InputStream inputStream = Resources.getResourceAsStream("mybatis-config.xml");SqlSessionFactory factory = new SqlSessionFactoryBuilder().build(inputStream);SqlSession sqlSession = factory.openSession();//这里不再调用SqlSession 的api,而是获得了接口对象,调用接口中的方法。UserMapper mapper = sqlSession.getMapper(UserMapper.class);List<User> list = mapper.getUserByName("tom");
}

原生MyBatis原理分析

初始化工作

解析配置文件

InputStream inputStream = Resources.getResourceAsStream("mybatis-config.xml");
//这一行代码正是初始化工作的开始。
SqlSessionFactory factory = new SqlSessionFactoryBuilder().build(inputStream);

进入源码分析:

// 1.我们最初调用的build
public SqlSessionFactory build(InputStream inputStream) {//调用了重载方法return build(inputStream, null, null);}// 2.调用的重载方法
public SqlSessionFactory build(InputStream inputStream, String environment, Properties properties) {try {//  XMLConfigBuilder是专门解析mybatis的配置文件的类XMLConfigBuilder parser = new XMLConfigBuilder(inputStream, environment, properties);//这里又调用了一个重载方法。parser.parse()的返回值是Configuration对象return build(parser.parse());} catch (Exception e) {throw ExceptionFactory.wrapException("Error building SqlSession.", e);} //省略部分代码}

下面进入对配置文件解析部分:

首先对Configuration对象进行介绍:

Configuration对象的结构和xml配置文件的对象几乎相同。

回顾一下xml中的配置标签有哪些:

properties(属性),settings(设置),typeAliases(类型别名),typeHandlers(类型处理器),objectFactory(对象工厂),mappers(映射器)等

Configuration也有对应的对象属性来封装它们:
(图片来自:https://blog.csdn.net/luanlouis/article/details/37744073)在这里插入图片描述
也就是说,初始化配置文件信息的本质就是创建Configuration对象,将解析的xml数据封装到Configuration内部的属性中。

//在创建XMLConfigBuilder时,它的构造方法中解析器XPathParser已经读取了配置文件
//3. 进入XMLConfigBuilder 中的 parse()方法。
public Configuration parse() {if (parsed) {throw new BuilderException("Each XMLConfigBuilder can only be used once.");}parsed = true;//parser是XPathParser解析器对象,读取节点内数据,<configuration>是MyBatis配置文件中的顶层标签parseConfiguration(parser.evalNode("/configuration"));//最后返回的是Configuration 对象return configuration;
}//4. 进入parseConfiguration方法
//此方法中读取了各个标签内容并封装到Configuration中的属性中。
private void parseConfiguration(XNode root) {try {//issue #117 read properties firstpropertiesElement(root.evalNode("properties"));Properties settings = settingsAsProperties(root.evalNode("settings"));loadCustomVfs(settings);loadCustomLogImpl(settings);typeAliasesElement(root.evalNode("typeAliases"));pluginElement(root.evalNode("plugins"));objectFactoryElement(root.evalNode("objectFactory"));objectWrapperFactoryElement(root.evalNode("objectWrapperFactory"));reflectorFactoryElement(root.evalNode("reflectorFactory"));settingsElement(settings);// read it after objectFactory and objectWrapperFactory issue #631environmentsElement(root.evalNode("environments"));databaseIdProviderElement(root.evalNode("databaseIdProvider"));typeHandlerElement(root.evalNode("typeHandlers"));mapperElement(root.evalNode("mappers"));} catch (Exception e) {throw new BuilderException("Error parsing SQL Mapper Configuration. Cause: " + e, e);}
}

到此对xml配置文件的解析就结束了(下文会对部分解析做详细介绍),回到步骤 2. 中调用的重载build方法。

// 5. 调用的重载方法
public SqlSessionFactory build(Configuration config) {//创建了DefaultSqlSessionFactory对象,传入Configuration对象。return new DefaultSqlSessionFactory(config);}

配置类方式

发散一下思路,既然解析xml是对Configuration中的属性进行复制,那么我们同样可以在一个类中创建Configuration对象,手动设置其中属性的值来达到配置的效果。

执行SQL

先简单介绍SqlSession

SqlSession是一个接口,它有两个实现类:DefaultSqlSession(默认)和SqlSessionManager(弃用,不做介绍)
SqlSession是MyBatis中用于和数据库交互的顶层类,通常将它与ThreadLocal绑定,一个会话使用一个SqlSession,并且在使用完毕后需要close。
在这里插入图片描述
SqlSession中的两个最重要的参数,configuration与初始化时的相同,Executor为执行器,

Executor:

Executor也是一个接口,他有三个常用的实现类BatchExecutor(重用语句并执行批量更新),ReuseExecutor(重用预处理语句prepared statements),SimpleExecutor(普通的执行器,默认)。

SqlSession API方式

继续分析,初始化完毕后,我们就要执行SQL了:

		SqlSession sqlSession = factory.openSession();String name = "tom";List<User> list = sqlSession.selectList("com.demo.mapper.UserMapper.getUserByName",params);

获得sqlSession

//6. 进入openSession方法。public SqlSession openSession() {//getDefaultExecutorType()传递的是SimpleExecutorreturn openSessionFromDataSource(configuration.getDefaultExecutorType(), null, false);}//7. 进入openSessionFromDataSource。
//ExecutorType 为Executor的类型,TransactionIsolationLevel为事务隔离级别,autoCommit是否开启事务
//openSession的多个重载方法可以指定获得的SeqSession的Executor类型和事务的处理
private SqlSession openSessionFromDataSource(ExecutorType execType, TransactionIsolationLevel level, boolean autoCommit) {Transaction tx = null;try {final Environment environment = configuration.getEnvironment();final TransactionFactory transactionFactory = getTransactionFactoryFromEnvironment(environment);tx = transactionFactory.newTransaction(environment.getDataSource(), level, autoCommit);//根据参数创建指定类型的Executorfinal Executor executor = configuration.newExecutor(tx, execType);//返回的是DefaultSqlSessionreturn new DefaultSqlSession(configuration, executor, autoCommit);} catch (Exception e) {closeTransaction(tx); // may have fetched a connection so lets call close()throw ExceptionFactory.wrapException("Error opening session.  Cause: " + e, e);} finally {ErrorContext.instance().reset();}}

执行sqlsession中的api

//8.进入selectList方法,多个重载方法。
public <E> List<E> selectList(String statement) {return this.selectList(statement, null);
}
public <E> List<E> selectList(String statement, Object parameter) {return this.selectList(statement, parameter, RowBounds.DEFAULT);
}public <E> List<E> selectList(String statement, Object parameter, RowBounds rowBounds) {try {//根据传入的全限定名+方法名从映射的Map中取出MappedStatement对象MappedStatement ms = configuration.getMappedStatement(statement);//调用Executor中的方法处理return executor.query(ms, wrapCollection(parameter), rowBounds, Executor.NO_RESULT_HANDLER);} catch (Exception e) {throw ExceptionFactory.wrapException("Error querying database.  Cause: " + e, e);} finally {ErrorContext.instance().reset();}}

介绍一下MappedStatement

  • 作用: MappedStatement与Mapper配置文件中的一个select/update/insert/delete节点相对应。mapper中配置的标签都被封装到了此对象中,主要用途是描述一条SQL语句。
  • **初始化过程:**回顾刚开始介绍的加载配置文件的过程中,会对mybatis-config.xml中的各个标签都进行解析,其中有 mappers标签用来引入mapper.xml文件或者配置mapper接口的目录。
 <select id="getUser" resultType="user" >select * from user where id=#{id}</select>

这样的一个select标签会在初始化配置文件时被解析封装成一个MappedStatement对象,然后存储在Configuration对象的mappedStatements属性中,mappedStatements 是一个HashMap,存储时key = 全限定类名 + 方法名,value = 对应的MappedStatement对象

  • 在configuration中对应的属性为
Map<String, MappedStatement> mappedStatements = new StrictMap<MappedStatement>("Mapped Statements collection")
  • 在XMLConfigBuilder中的处理:
  private void parseConfiguration(XNode root) {try {// 省略其他标签的处理mapperElement(root.evalNode("mappers"));} catch (Exception e) {throw new BuilderException("Error parsing SQL Mapper Configuration. Cause: " + e, e);}}

继续源码中的步骤,进入 executor.query()

//此方法在SimpleExecutor的父类BaseExecutor中实现
public <E> List<E> query(MappedStatement ms, Object parameter, RowBounds rowBounds, ResultHandler resultHandler) throws SQLException {//根据传入的参数动态获得SQL语句,最后返回用BoundSql对象表示BoundSql boundSql = ms.getBoundSql(parameter);//为本次查询创建缓存的KeyCacheKey key = createCacheKey(ms, parameter, rowBounds, boundSql);return query(ms, parameter, rowBounds, resultHandler, key, boundSql);}//进入query的重载方法中
public <E> List<E> query(MappedStatement ms, Object parameter, RowBounds rowBounds, ResultHandler resultHandler, CacheKey key, BoundSql boundSql) throws SQLException {ErrorContext.instance().resource(ms.getResource()).activity("executing a query").object(ms.getId());if (closed) {throw new ExecutorException("Executor was closed.");}if (queryStack == 0 && ms.isFlushCacheRequired()) {clearLocalCache();}List<E> list;try {queryStack++;list = resultHandler == null ? (List<E>) localCache.getObject(key) : null;if (list != null) {handleLocallyCachedOutputParameters(ms, key, parameter, boundSql);} else {// 如果缓存中没有本次查找的值,那么从数据库中查询list = queryFromDatabase(ms, parameter, rowBounds, resultHandler, key, boundSql);}} finally {queryStack--;}if (queryStack == 0) {for (DeferredLoad deferredLoad : deferredLoads) {deferredLoad.load();}// issue #601deferredLoads.clear();if (configuration.getLocalCacheScope() == LocalCacheScope.STATEMENT) {// issue #482clearLocalCache();}}return list;}//从数据库查询
private <E> List<E> queryFromDatabase(MappedStatement ms, Object parameter, RowBounds rowBounds, ResultHandler resultHandler, CacheKey key, BoundSql boundSql) throws SQLException {List<E> list;localCache.putObject(key, EXECUTION_PLACEHOLDER);try {// 查询的方法list = doQuery(ms, parameter, rowBounds, resultHandler, boundSql);} finally {localCache.removeObject(key);}// 将查询结果放入缓存localCache.putObject(key, list);if (ms.getStatementType() == StatementType.CALLABLE) {localOutputParameterCache.putObject(key, parameter);}return list;}// SimpleExecutor中实现父类的doQuery抽象方法
public <E> List<E> doQuery(MappedStatement ms, Object parameter, RowBounds rowBounds, ResultHandler resultHandler, BoundSql boundSql) throws SQLException {Statement stmt = null;try {Configuration configuration = ms.getConfiguration();// 传入参数创建StatementHanlder对象来执行查询StatementHandler handler = configuration.newStatementHandler(wrapper, ms, parameter, rowBounds, resultHandler, boundSql);// 创建jdbc中的statement对象stmt = prepareStatement(handler, ms.getStatementLog());// StatementHandler进行处理return handler.query(stmt, resultHandler);} finally {closeStatement(stmt);}}// 创建Statement的方法
private Statement prepareStatement(StatementHandler handler, Log statementLog) throws SQLException {Statement stmt;//条代码中的getConnection方法经过重重调用最后会调用openConnection方法,从连接池中获得连接。Connection connection = getConnection(statementLog);stmt = handler.prepare(connection, transaction.getTimeout());handler.parameterize(stmt);return stmt;}
//从连接池获得连接的方法
protected void openConnection() throws SQLException {if (log.isDebugEnabled()) {log.debug("Opening JDBC Connection");}//从连接池获得连接connection = dataSource.getConnection();if (level != null) {connection.setTransactionIsolation(level.getLevel());}setDesiredAutoCommit(autoCommit);}//进入StatementHandler进行处理的query,StatementHandler中默认的是PreparedStatementHandler
public <E> List<E> query(Statement statement, ResultHandler resultHandler) throws SQLException {PreparedStatement ps = (PreparedStatement) statement;//原生jdbc的执行ps.execute();//处理结果返回。return resultSetHandler.handleResultSets(ps);}

接口方式

回顾一下写法:

public static void main(String[] args) {//前三步都相同InputStream inputStream = Resources.getResourceAsStream("mybatis-config.xml");SqlSessionFactory factory = new SqlSessionFactoryBuilder().build(inputStream);SqlSession sqlSession = factory.openSession();//这里不再调用SqlSession 的api,而是获得了接口对象,调用接口中的方法。UserMapper mapper = sqlSession.getMapper(UserMapper.class);List<User> list = mapper.getUserByName("tom");
}

思考一个问题,通常的Mapper接口我们都没有实现的方法却可以使用,是为什么呢?答案很简单 动态代理


开始之前介绍一下MyBatis初始化时对接口的处理:MapperRegistry是Configuration中的一个属性,它内部维护一个HashMap用于存放mapper接口的工厂类,每个接口对应一个工厂类。mappers中可以配置接口的包路径,或者某个具体的接口类。

<!-- 将包内的映射器接口实现全部注册为映射器 -->
<mappers><mapper class="com.demo.mapper.UserMapper"/><package name="com.demo.mapper"/>
</mappers>
  • 当解析mappers标签时,它会判断解析到的是mapper配置文件时,会再将对应配置文件中的增删改查标签一 一封装成MappedStatement对象,存入mappedStatements中。(上文介绍了)
  • 当判断解析到接口时,会创建此接口对应的MapperProxyFactory对象,存入HashMap中,key = 接口的字节码对象,value = 此接口对应的MapperProxyFactory对象。
//MapperRegistry类
public class MapperRegistry {private final Configuration config;//这个类中维护一个HashMap存放MapperProxyFactoryprivate final Map<Class<?>, MapperProxyFactory<?>> knownMappers = new HashMap<>();//解析到接口时添加接口工厂类的方法public <T> void addMapper(Class<T> type) {if (type.isInterface()) {if (hasMapper(type)) {throw new BindingException("Type " + type + " is already known to the MapperRegistry.");}boolean loadCompleted = false;try {//重点在这行,以接口类的class对象为key,value为其对应的工厂对象,构造方法中指定了接口对象knownMappers.put(type, new MapperProxyFactory<>(type));// It's important that the type is added before the parser is run// otherwise the binding may automatically be attempted by the// mapper parser. If the type is already known, it won't try.MapperAnnotationBuilder parser = new MapperAnnotationBuilder(config, type);parser.parse();loadCompleted = true;} finally {if (!loadCompleted) {knownMappers.remove(type);}}}}
}

正文:
进入sqlSession.getMapper(UserMapper.class)中

//DefaultSqlSession中的getMapper
public <T> T getMapper(Class<T> type) {return configuration.<T>getMapper(type, this);
}//configuration中的给getMapper
public <T> T getMapper(Class<T> type, SqlSession sqlSession) {return mapperRegistry.getMapper(type, sqlSession);
}//MapperRegistry中的getMapper
public <T> T getMapper(Class<T> type, SqlSession sqlSession) {//从MapperRegistry中的HashMap中拿MapperProxyFactoryfinal MapperProxyFactory<T> mapperProxyFactory = (MapperProxyFactory<T>) knownMappers.get(type);if (mapperProxyFactory == null) {throw new BindingException("Type " + type + " is not known to the MapperRegistry.");}try {// 通过动态代理工厂生成示例。return mapperProxyFactory.newInstance(sqlSession);} catch (Exception e) {throw new BindingException("Error getting mapper instance. Cause: " + e, e);}
}//MapperProxyFactory类中的newInstance方法public T newInstance(SqlSession sqlSession) {// 创建了JDK动态代理的Handler类final MapperProxy<T> mapperProxy = new MapperProxy<>(sqlSession, mapperInterface, methodCache);// 调用了重载方法return newInstance(mapperProxy);}//MapperProxy类,实现了InvocationHandler接口
public class MapperProxy<T> implements InvocationHandler, Serializable {//省略部分源码	private final SqlSession sqlSession;private final Class<T> mapperInterface;private final Map<Method, MapperMethod> methodCache;// 构造,传入了SqlSession,说明每个session中的代理对象的不同的!public MapperProxy(SqlSession sqlSession, Class<T> mapperInterface, Map<Method, MapperMethod> methodCache) {this.sqlSession = sqlSession;this.mapperInterface = mapperInterface;this.methodCache = methodCache;}//省略部分源码
}//重载的方法,由动态代理创建新示例返回。
protected T newInstance(MapperProxy<T> mapperProxy) {return (T) Proxy.newProxyInstance(mapperInterface.getClassLoader(), new Class[] { mapperInterface }, mapperProxy);}

在动态代理返回了示例后,我们就可以直接调用mapper类中的方法了,说明在MapperProxy中的invoke方法中已经为我们实现了方法。

public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {try {//判断调用是是不是Object中定义的方法,toString,hashCode这类非。是的话直接放行。if (Object.class.equals(method.getDeclaringClass())) {return method.invoke(this, args);} else if (isDefaultMethod(method)) {return invokeDefaultMethod(proxy, method, args);}} catch (Throwable t) {throw ExceptionUtil.unwrapThrowable(t);} final MapperMethod mapperMethod = cachedMapperMethod(method);// 重点在这:MapperMethod最终调用了执行的方法return mapperMethod.execute(sqlSession, args);}public Object execute(SqlSession sqlSession, Object[] args) {Object result;//判断mapper中的方法类型,最终调用的还是SqlSession中的方法switch (command.getType()) {case INSERT: {Object param = method.convertArgsToSqlCommandParam(args);result = rowCountResult(sqlSession.insert(command.getName(), param));break;}case UPDATE: {Object param = method.convertArgsToSqlCommandParam(args);result = rowCountResult(sqlSession.update(command.getName(), param));break;}case DELETE: {Object param = method.convertArgsToSqlCommandParam(args);result = rowCountResult(sqlSession.delete(command.getName(), param));break;}case SELECT:if (method.returnsVoid() && method.hasResultHandler()) {executeWithResultHandler(sqlSession, args);result = null;} else if (method.returnsMany()) {result = executeForMany(sqlSession, args);} else if (method.returnsMap()) {result = executeForMap(sqlSession, args);} else if (method.returnsCursor()) {result = executeForCursor(sqlSession, args);} else {Object param = method.convertArgsToSqlCommandParam(args);result = sqlSession.selectOne(command.getName(), param);if (method.returnsOptional() &&(result == null || !method.getReturnType().equals(result.getClass()))) {result = Optional.ofNullable(result);}}break;case FLUSH:result = sqlSession.flushStatements();break;default:throw new BindingException("Unknown execution method for: " + command.getName());}if (result == null && method.getReturnType().isPrimitive() && !method.returnsVoid()) {throw new BindingException("Mapper method '" + command.getName()+ " attempted to return null from a method with a primitive return type (" + method.getReturnType() + ").");}return result;}

http://chatgpt.dhexx.cn/article/ubdwf7WQ.shtml

相关文章

【MyBatis学习笔记九】——MyBatis原理

一、Mybatis工作原理图 mybatis 原理图如下所示&#xff1a; 二、工作原理解析 mybatis应用程序通过SqlSessionFactoryBuilder从mybatis-config.xml配置文件&#xff08;也可以用Java文件配置的方式&#xff0c;需要添加Configuration&#xff09;来构建SqlSessionFactory&…

【mybatis原理工作原理】

文章目录 mybatis原理&#xff1a;mybatis缓存机制 mybatis原理&#xff1a; mybatis的工作原理就是&#xff1a;先封装sql&#xff0c;接着调用jdbc操作数据库&#xff0c;最后把数据库返回的表结果封装成java类。 通过代码实现jdbc查询操作&#xff1a; mybatis-config.xm…

mybatis原理(含图)

上面中流程就是MyBatis内部核心流程&#xff0c;每一步流程的详细说明如下文所述&#xff1a; &#xff08;1&#xff09;读取MyBatis的配置文件。mybatis-config.xml为MyBatis的全局配置文件&#xff0c;用于配置数据库连接信息。 &#xff08;2&#xff09;加载映射文件。映…

MyBatis原理分析

是什么? MyBatis 是一款优秀的持久层框架&#xff0c;它支持定制化 SQL、存储过程以及高级映射。MyBatis 避免了几乎所有的 JDBC 代码和手动设置参数以及获取结果集。MyBatis可以使用简单的 XML 或注解来配置和映射原生类型、接口和 Java 的 POJO&#xff08;Plain Old Java …

Spring 整合 Mybatis 原理

目录 Mybatis的基本工作原理分析需要解决的问题Spring中Bean的产生过程解决问题解决方案FactoryBean Import总结优化 Mybatis的基本工作原理 在 Mybatis 中&#xff0c;我们可以使用一个接口去定义要执行 sql&#xff0c;简化代码如下&#xff1a;定义一个接口&#xff0c;Sel…

Springboot整合mybatis原理

文章目录 加载过程1、读取META-INF/spring.factories配置文件里需要自动装载的类2、解析MybatisAutoConfiguration类里的注解信息&#xff0c;将需要管理的Bean注册到Spring容器2.1 注册SqlSessionFactory&#xff0c;并根据mapper配置文件解析出dao与具体jdbc操作、resultMap与…

【mybatis原理】

mybatis mybatis原理mybatis框架分层架构核心接口和对象mapper接口与xml的映射mybatis执行过程mybatis执行时序图一级缓存和二级缓存一级缓存二级缓存 mybatis核心流程1、初始化阶段2、代理阶段3、数据读写阶段 mybatis如何获取数据源mybatis如何获取执行SQLMyBatis 如何执行 s…

Mybatis原理

文章目录 - 什么是Mybatis&#xff1f;- Mybaits的优点&#xff1a;- MyBatis框架的缺点&#xff1a;- MyBatis与Hibernate有哪些不同&#xff1f;- 架构MyBatis缓存一级缓存一级缓存和sqlsession之间的关系一级缓存的生命周期有多长&#xff1f;SqlSession 一级缓存的工作流程…

深入详解Mybatis的架构原理与6大核心流程

MyBatis 是 Java 生态中非常著名的一款 ORM 框架&#xff0c;目前在一线互联网大厂中应用广泛&#xff0c;Mybatis已经成为了一个必会框架。 如果你想要进入一线大厂&#xff0c;能够熟练使用 MyBatis 开发已经是一项非常基本的技能&#xff0c;同时大厂也更希望自己的开发人员…

总结Mybatis的原理

一、什么是Mybatis Mybatis是一个半ORM&#xff08;对象关系映射&#xff09;框架&#xff0c;底层封装了JDBC&#xff0c;是程序员在开发时只需要关注SQL语句本身&#xff0c;不需要花费精力去处理加载驱动、创建连接、创建statement等繁杂的过程。MyBatis 可以使用简单的 XM…

MyBatis基本工作原理介绍

1、MyBatis基本工作原理介绍 计算机的基本工作就是存储和计算&#xff0c;而MyBatis是存储领域的利器。MyBatis的基本工作原理就是&#xff1a;先封装SQL&#xff0c;接着调用JDBC操作数据库&#xff0c;最后把数据库返回的表结果封装成Java类。 2、MyBatis的核心流程介绍 m…

Mybatis 工作原理详解

目录 Mybatis持久层框架 结果集进行ORM映射 步骤解析 1、获取结果集及结果映射入口 2、开始ORM映射接口 3、数据库结果集解析&#xff0c;完成ORM映射 4、保存并获取ORM映射后的结果集 参数传递方式 顺序传参法 Param注解传参法 Map传参法 Java Bean传参法 mybat…

《深入理解mybatis原理》 MyBatis的架构设计以及实例分析

MyBatis是目前非常流行的ORM框架&#xff0c;它的功能很强大&#xff0c;然而其实现却比较简单、优雅。本文主要讲述MyBatis的架构设计思路&#xff0c;并且讨论MyBatis的几个核心部件&#xff0c;然后结合一个select查询实例&#xff0c;深入代码&#xff0c;来探究MyBatis的实…

【图片压缩】三个方法压缩图片体积

图片体积过大&#xff0c;会占用电脑过多的容量&#xff0c;也有可能无法发送给其他人。我们可以压缩图片体积来解决问题。分享三个方法压缩图片体积&#xff1a; 方法一&#xff1a;改变图片格式 首先是改变图片的格式&#xff0c;如果你不介意压缩之后的图片画质损失&#…

Windows不同压缩软件、压缩算法、压缩率详细对比测试与选择

上次写了图片压缩&#xff0c;这倒让我想起几年前看过的一个很有意思的东西 那就是这张鸭子图&#xff1a; 不过微信会压缩图片&#xff0c;你可以打开这个链接&#xff1a;http://2.im.guokr.com/F70Kn-4wz7aF5Yejf9W3g6kO4exDBqVEb0TumQmxy5MiAQAAEAEAAEpQ.jpg 来获取原图 …

为什么压缩图片和压缩

为什么要压缩图片&#xff1f; 表示图像需要大量的数据&#xff0c;但图像数据是高度相关的&#xff0c;或者说存在冗余(Redundancy)信息&#xff0c;去掉这些冗余信息后可以有效压缩图像&#xff0c;同时又不会损害图像的有效信息。 视网膜上有两种感光细胞&#xff0c;能够…

2款免费的图片压缩工具

今天写这篇文章的目的&#xff0c;主要是为大家介绍2款免费的图片压缩工具&#xff0c;在工作和学习中这也是一项必备的技能。比如当你遇到比较大的图片需要发送的时候&#xff0c;或者对图片的大小有强制要求的时候&#xff0c;这些小工具就派上了用场。 网上也有一些付费的压…

如何批量压缩图片体积大小kb?

工作中&#xff0c;我们在使用图片素材时&#xff0c;图片kb体积过大怎么办&#xff1f; 通常我们会直接在电脑上将图片调整成我们想要的尺寸大小&#xff0c;可以利用的工具有photoshop或者截图的方法&#xff0c;这对于有些小伙伴来说不是很难的事情&#xff0c;今天我就不做…

图片批量压缩方法及步骤

图片批量压缩方法及步骤&#xff01;平常我们会将手机拍摄的照片传输到电脑里保存&#xff0c;时间久了后电脑中会有大量的图片&#xff0c;这些图片大都是1M-2M的体积大小&#xff0c;这些图片会占用大量的电脑磁盘空间&#xff0c;可能会导致电脑变得很卡等现象。但是又不忍心…

银河麒麟批量压缩图片的方法

适用系统&#xff1a;银河麒麟V10(SP1)&#xff0c;CPU&#xff1a;Kirin990&#xff0c;架构&#xff1a;aarch64。 软件商店下载“简单图像压缩转换软件”。桌面左下角点开菜单搜索“Simple Image Reducer”&#xff0c;右键添加到桌面快捷方式。打开Simple Image Reducer。…