Mybatis源码学习(三)SqlSession详解
Mybatis源码学习(三)SqlSession详解
- 前言
- 1. SqlSession源码详解
- 2. DefaultSqlSession源码详解
- 2.1DefaultSqlSession源码
- 2.2 configuration.getMappedStatement(statement)
- 2.3 Executor
- 3. SqlSessionManager源码详解
- 3.1 私有的构造方法
- 3.2 SqlSession的代理类SqlSessionInterceptor
- 3.3 其他事务等方法
- 总结
- 文章链接
前言
上一章节我们学习了SqlSessionFactory的源码,SqlSessionFactory中的方法都是围绕着SqlSession来的.,那么SqlSession又是什么东东呢?这一章节我们就来揭开它的真面目吧!
1. SqlSession源码详解
SqlSession是一个接口类,文档上注明它是mybatis的一个主要的java 接口.官方都说很重要了,那肯定是非常重要.它的主要功能是执行命令,获取mapper和管理事务.
SqlSession有两个实现类,分别是DefaultSqlSession和SqlSessionManager,上一章节也出现过SqlSessionManager,大家还记得吗?SqlSessionManager既实现了SqlSession也实现了SqlSessionFactory.话不多说,详细学习以下两个类的源码吧!
2. DefaultSqlSession源码详解
2.1DefaultSqlSession源码
public class DefaultSqlSession implements SqlSession {/*** 全局配置对象*/private final Configuration configuration;/*** sql执行器*/private final Executor executor;/*** 是否自动提交*/private final boolean autoCommit;/*** 是否脏数据*/private boolean dirty;/*** 游标列表*/private List<Cursor<?>> cursorList;/**构造函数* @param configuration 核心配置对象* @param executor sql执行器* @param autoCommit 是否自动提交*/public DefaultSqlSession(Configuration configuration, Executor executor, boolean autoCommit) {this.configuration = configuration;this.executor = executor;this.dirty = false;this.autoCommit = autoCommit;}/**构造函数* @param configuration 核心配置对象* @param executor sql执行器*/public DefaultSqlSession(Configuration configuration, Executor executor) {this(configuration, executor, false);}/**查询单条数据并返回对象* @param statement the statement* @param <T> 返回对象类型* @return 对象*/@Overridepublic <T> T selectOne(String statement) {return this.selectOne(statement, null);}/**查询单条数据并返回对象* @param statement the statement* @param parameter sql语句参数* @param <T> 返回对象类型* @return 对象*/@Overridepublic <T> T selectOne(String statement, Object parameter) {// Popular vote was to return null on 0 results and throw exception on too many.//调用selectListList<T> list = this.selectList(statement, parameter);if (list.size() == 1) {//结果为1条数据时,返回第0条return list.get(0);} else if (list.size() > 1) {//结果数大于1时,抛出异常throw new TooManyResultsException("Expected one result (or null) to be returned by selectOne(), but found: " + list.size());} else {//返回nullreturn null;}}/**map查询* @param statement Unique identifier matching the statement to use.* @param mapKey The property to use as key for each value in the list.* @param <K> 返回的map的key的泛型* @param <V> 返回的map的值的泛型* @return 返回map<K,V>*/@Overridepublic <K, V> Map<K, V> selectMap(String statement, String mapKey) {//调用selectMapreturn this.selectMap(statement, null, mapKey, RowBounds.DEFAULT);}/**map查询* @param statement Unique identifier matching the statement to use.* @param parameter A parameter object to pass to the statement.* @param mapKey The property to use as key for each value in the list.* @param <K> 返回的map的key的泛型* @param <V> 返回的map的值的泛型* @return 返回map<K,V>*/@Overridepublic <K, V> Map<K, V> selectMap(String statement, Object parameter, String mapKey) {//调用selectMapreturn this.selectMap(statement, parameter, mapKey, RowBounds.DEFAULT);}/**map查询* @param statement Unique identifier matching the statement to use.* @param parameter A parameter object to pass to the statement.* @param mapKey The property to use as key for each value in the list.* @param rowBounds Bounds to limit object retrieval* @param <K> 返回的map的key的泛型* @param <V> 返回的map的值的泛型* @return 返回map<K,V>*/@Overridepublic <K, V> Map<K, V> selectMap(String statement, Object parameter, String mapKey, RowBounds rowBounds) {//调用selectList获取结果final List<? extends V> list = selectList(statement, parameter, rowBounds);//初始化一个默认的Map结果处理器final DefaultMapResultHandler<K, V> mapResultHandler = new DefaultMapResultHandler<>(mapKey,configuration.getObjectFactory(), configuration.getObjectWrapperFactory(), configuration.getReflectorFactory());//初始化一个默认的结果上下文对象final DefaultResultContext<V> context = new DefaultResultContext<>();for (V o : list) {//遍历结果列表,放入context中context.nextResultObject(o);//使用Map结果处理器处理上下文mapResultHandler.handleResult(context);}//从结果处理器中获取处理完的map<K,V>返回return mapResultHandler.getMappedResults();}/**游标查询* @param statement Unique identifier matching the statement to use.* @param <T> 返回对象类型* @return 对象*/@Overridepublic <T> Cursor<T> selectCursor(String statement) {return selectCursor(statement, null);}/**游标查询* @param statement Unique identifier matching the statement to use.* @param parameter A parameter object to pass to the statement.* @param <T> 返回对象类型* @return 对象*/@Overridepublic <T> Cursor<T> selectCursor(String statement, Object parameter) {return selectCursor(statement, parameter, RowBounds.DEFAULT);}/**游标查询* @param statement Unique identifier matching the statement to use.* @param parameter A parameter object to pass to the statement.* @param rowBounds Bounds to limit object retrieval* @param <T> 返回对象类型* @return 对象*/@Overridepublic <T> Cursor<T> selectCursor(String statement, Object parameter, RowBounds rowBounds) {try {//使用全局配置对象中的mappedStatements获取MappedStatement对象MappedStatement ms = configuration.getMappedStatement(statement);//调用sql处理器查询Cursor<T> cursor = executor.queryCursor(ms, wrapCollection(parameter), rowBounds);//把游标注册到游标列表中,方便后续统一管理游标registerCursor(cursor);return cursor;} catch (Exception e) {throw ExceptionFactory.wrapException("Error querying database. Cause: " + e, e);} finally {ErrorContext.instance().reset();}}/**查询列表* @param statement Unique identifier matching the statement to use.* @param <E> 结果的泛型* @return 结果列表*/@Overridepublic <E> List<E> selectList(String statement) {return this.selectList(statement, null);}/**查询列表* @param statement Unique identifier matching the statement to use.* @param parameter A parameter object to pass to the statement.* @param <E> 结果的泛型* @return 结果列表*/@Overridepublic <E> List<E> selectList(String statement, Object parameter) {//调用selectListreturn this.selectList(statement, parameter, RowBounds.DEFAULT);}/**查询列表* @param statement Unique identifier matching the statement to use.* @param parameter A parameter object to pass to the statement.* @param rowBounds Bounds to limit object retrieval* @param <E> 结果的泛型* @return 结果列表*/@Overridepublic <E> List<E> selectList(String statement, Object parameter, RowBounds rowBounds) {try {//使用全局配置对象中的mappedStatements获取MappedStatement对象MappedStatement ms = configuration.getMappedStatement(statement);//调用sql处理器查询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();}}/**带结果处理器的查询* @param statement Unique identifier matching the statement to use.* @param parameter A parameter object to pass to the statement.* @param handler ResultHandler that will handle each retrieved row*/@Overridepublic void select(String statement, Object parameter, ResultHandler handler) {//调用selectselect(statement, parameter, RowBounds.DEFAULT, handler);}/**带结果处理器的查询* @param statement Unique identifier matching the statement to use.* @param handler ResultHandler that will handle each retrieved row*/@Overridepublic void select(String statement, ResultHandler handler) {select(statement, null, RowBounds.DEFAULT, handler);}/**带结果处理器的查询* @param statement Unique identifier matching the statement to use.* @param parameter the parameter* @param rowBounds RowBound instance to limit the query results* @param handler*/@Overridepublic void select(String statement, Object parameter, RowBounds rowBounds, ResultHandler handler) {try {//使用全局配置对象中的mappedStatements获取MappedStatement对象MappedStatement ms = configuration.getMappedStatement(statement);//调用sql处理器查询executor.query(ms, wrapCollection(parameter), rowBounds, handler);} catch (Exception e) {throw ExceptionFactory.wrapException("Error querying database. Cause: " + e, e);} finally {ErrorContext.instance().reset();}}/**插入数据* @param statement Unique identifier matching the statement to execute.* @return 影响的行数*/@Overridepublic int insert(String statement) {//调用insertreturn insert(statement, null);}/**插入数据* @param statement Unique identifier matching the statement to execute.* @param parameter A parameter object to pass to the statement.* @return 影响的行数*/@Overridepublic int insert(String statement, Object parameter) {//调用updatereturn update(statement, parameter);}/**更新数据* @param statement Unique identifier matching the statement to execute.* @return 影响的行数*/@Overridepublic int update(String statement) {//调用updatereturn update(statement, null);}/**更新数据* @param statement Unique identifier matching the statement to execute.* @param parameter A parameter object to pass to the statement.* @return 影响的行数*/@Overridepublic int update(String statement, Object parameter) {try {//设置脏数据状态为truedirty = true;//使用全局配置对象中的mappedStatements获取MappedStatement对象MappedStatement ms = configuration.getMappedStatement(statement);//调用sql处理器更新return executor.update(ms, wrapCollection(parameter));} catch (Exception e) {throw ExceptionFactory.wrapException("Error updating database. Cause: " + e, e);} finally {ErrorContext.instance().reset();}}/**删除数据* @param statement Unique identifier matching the statement to execute.* @return 影响的行数*/@Overridepublic int delete(String statement) {//调用updatereturn update(statement, null);}/**删除数据* @param statement Unique identifier matching the statement to execute.* @param parameter A parameter object to pass to the statement.* @return 影响的行数*/@Overridepublic int delete(String statement, Object parameter) {//调用更新return update(statement, parameter);}/*** 提交事务*/@Overridepublic void commit() {commit(false);}/**提交事务* @param force 是否强制提交*/@Overridepublic void commit(boolean force) {try {//调用执行器提交事务executor.commit(isCommitOrRollbackRequired(force));//设置脏数据状态为falsedirty = false;} catch (Exception e) {throw ExceptionFactory.wrapException("Error committing transaction. Cause: " + e, e);} finally {ErrorContext.instance().reset();}}/*** 回滚事务*/@Overridepublic void rollback() {rollback(false);}/**回滚事务* @param force forces connection rollback*/@Overridepublic void rollback(boolean force) {try {//调用执行器回滚事务executor.rollback(isCommitOrRollbackRequired(force));//设置脏数据状态为falsedirty = false;} catch (Exception e) {throw ExceptionFactory.wrapException("Error rolling back transaction. Cause: " + e, e);} finally {ErrorContext.instance().reset();}}/**批量处理* @return 返回批量处理的结果*/@Overridepublic List<BatchResult> flushStatements() {try {//调用执行器进行批量操作return executor.flushStatements();} catch (Exception e) {throw ExceptionFactory.wrapException("Error flushing statements. Cause: " + e, e);} finally {ErrorContext.instance().reset();}}/*** 关闭sqlsession*/@Overridepublic void close() {try {//调用执行器进行关闭executor.close(isCommitOrRollbackRequired(false));//关闭所有游标closeCursors();//设置脏数据状态为falsedirty = false;} finally {ErrorContext.instance().reset();}}/*** 关闭全部游标*/private void closeCursors() {if (cursorList != null && !cursorList.isEmpty()) {for (Cursor<?> cursor : cursorList) {//遍历游标列表,进行关闭操作try {cursor.close();} catch (IOException e) {throw ExceptionFactory.wrapException("Error closing cursor. Cause: " + e, e);}}//清空游标cursorList.clear();}}/**获取全局配置对象* @return 全局配置对象*/@Overridepublic Configuration getConfiguration() {return configuration;}/**获取Mapper<T>的动态代理类* @param type Mapper interface class* @param <T> 返回对象的泛型* @return Mapper接口的动态代理类*/@Overridepublic <T> T getMapper(Class<T> type) {//从核心配置对象中获取mapper, 实际是从mapperRegistry中获取mapper接口的代理工厂,使用代理工厂创建的动态代理类return configuration.getMapper(type, this);}/**获取数据库连接* @return 数据库连接*/@Overridepublic Connection getConnection() {try {//调用执行器获取连接return executor.getTransaction().getConnection();} catch (SQLException e) {throw ExceptionFactory.wrapException("Error getting a new connection. Cause: " + e, e);}}/*** 清除缓存*/@Overridepublic void clearCache() {//调用执行器清除本地缓存executor.clearLocalCache();}/**注册游标* @param cursor 游标对象* @param <T> 泛型*/private <T> void registerCursor(Cursor<T> cursor) {if (cursorList == null) {cursorList = new ArrayList<>();}//把游标加入到cursorListcursorList.add(cursor);}/**判断是否需求提交或者回滚* @param force 是否强制提交或回滚* @return 是否需求提交或者回滚*/private boolean isCommitOrRollbackRequired(boolean force) {//如果不是自动提交并且有脏数据返回true//如果强制提交或回滚返回truereturn (!autoCommit && dirty) || force;}/**将Collection或者数组类型的参数转换成Map* @param object 参数对象* @return 包装后的对象*/private Object wrapCollection(final Object object) {return ParamNameResolver.wrapToMapIfCollection(object, null);}/*** @deprecated Since 3.5.5*/@Deprecatedpublic static class StrictMap<V> extends HashMap<String, V> {private static final long serialVersionUID = -5741767162221585340L;@Overridepublic V get(Object key) {if (!super.containsKey(key)) {throw new BindingException("Parameter '" + key + "' not found. Available parameters are " + this.keySet());}return super.get(key);}}}
DefaultSqlSession的方法分类
1.selectOne(),selectMap(),selectList()为一类,它们的实现都是通过selectList()得到的结构进行处理的
2.selectCursor()
3.select()
4.insert(),update(),delete()为一类,它们的实现都是通过update()
5.实现的事务相关的和其他方法
2.2 configuration.getMappedStatement(statement)
configuration的内部是维护了一个Map<String, MappedStatement> mappedStatements
在获取之前如果还有未完成的Statements,会先执行buildAllStatements()
public MappedStatement getMappedStatement(String id, boolean validateIncompleteStatements) {if (validateIncompleteStatements) {buildAllStatements();}return mappedStatements.get(id);
}
那这个Map是什么时候插入值的呢,我们进行代码的跟踪,有没有很眼熟,是上一章的最后一节我们说到的解析所有的Mapper配置
在解析的过程里,会把MappedStatement的id属性作为key,MappedStatement作为值放入到mappedStatements中
ps: 查看调用关系快捷键 Ctrl + Alt + H
2.3 Executor
我们通过调用栈来看下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);//通过configuration创建一个Executorfinal Executor executor = configuration.newExecutor(tx, execType);return 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();}}private SqlSession openSessionFromConnection(ExecutorType execType, Connection connection) {try {boolean autoCommit;try {autoCommit = connection.getAutoCommit();} catch (SQLException e) {// Failover to true, as most poor drivers// or databases won't support transactionsautoCommit = true;}final Environment environment = configuration.getEnvironment();final TransactionFactory transactionFactory = getTransactionFactoryFromEnvironment(environment);final Transaction tx = transactionFactory.newTransaction(connection);//通过configuration创建一个Executorfinal Executor executor = configuration.newExecutor(tx, execType);return new DefaultSqlSession(configuration, executor, autoCommit);} catch (Exception e) {throw ExceptionFactory.wrapException("Error opening session. Cause: " + e, e);} finally {ErrorContext.instance().reset();}}
public Executor newExecutor(Transaction transaction, ExecutorType executorType)代码
public Executor newExecutor(Transaction transaction, ExecutorType executorType) {//为空返回默认的executorType ExecutorType.SIMPLEexecutorType = executorType == null ? defaultExecutorType : executorType;executorType = executorType == null ? ExecutorType.SIMPLE : executorType;Executor 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;
}
interceptorChain.pluginAll(executor)
public Object pluginAll(Object target) {for (Interceptor interceptor : interceptors) {target = interceptor.plugin(target);}return target;
}
interceptor.plugin(target)
default Object plugin(Object target) {return Plugin.wrap(target, this);
}
Plugin.wrap(target, this)
public static Object wrap(Object target, Interceptor interceptor) {//获取当前的interceptor上的注解中定义的Signature[],把需要代理的类和方法放入Map中Map<Class<?>, Set<Method>> signatureMap = getSignatureMap(interceptor);Class<?> type = target.getClass();//匹配当前类有没有需要被代理的接口,有则返回代理对象,无返回原对象Class<?>[] interfaces = getAllInterfaces(type, signatureMap);if (interfaces.length > 0) {return Proxy.newProxyInstance(type.getClassLoader(),interfaces,new Plugin(target, interceptor, signatureMap));}return target;
}
MyInterceptor和PageInterceptor类上的@Intercepts注解
此处定义的都是对Executor类的下面两个方法进行代理
query(MappedStatement ms, Object parameter, RowBounds rowBounds, ResultHandler resultHandler, CacheKey cacheKey, BoundSql boundSql)
query(MappedStatement ms, Object parameter, RowBounds rowBounds, ResultHandler resultHandler)
最后代理两次后返回的Executor类
3. SqlSessionManager源码详解
3.1 私有的构造方法
//内部的SqlSessionFactory,为实现SqlSessionFactory相关接口而使用private final SqlSessionFactory sqlSessionFactory;//内部的SqlSession代理类,为实现SqlSession相关接口而使用private final SqlSession sqlSessionProxy;//ThreadLocal<SqlSession> 事务相关等方法操作是使用private final ThreadLocal<SqlSession> localSqlSession = new ThreadLocal<>();//私有构造函数private SqlSessionManager(SqlSessionFactory sqlSessionFactory) {this.sqlSessionFactory = sqlSessionFactory;this.sqlSessionProxy = (SqlSession) Proxy.newProxyInstance(SqlSessionFactory.class.getClassLoader(),new Class[]{SqlSession.class},new SqlSessionInterceptor());}
3.2 SqlSession的代理类SqlSessionInterceptor
private class SqlSessionInterceptor implements InvocationHandler {public SqlSessionInterceptor() {// Prevent Synthetic Access}@Overridepublic Object invoke(Object proxy, Method method, Object[] args) throws Throwable {//从LocalThread中获取SqlSessionfinal SqlSession sqlSession = SqlSessionManager.this.localSqlSession.get();if (sqlSession != null) {//LocalThread中有SqlSession,则使用try {return method.invoke(sqlSession, args);} catch (Throwable t) {throw ExceptionUtil.unwrapThrowable(t);}} else {//LocalThread中无SqlSession,获取一个SqlSessiontry (SqlSession autoSqlSession = openSession()) {try {final Object result = method.invoke(autoSqlSession, args);//手动提交autoSqlSession.commit();return result;} catch (Throwable t) {//手动回滚autoSqlSession.rollback();throw ExceptionUtil.unwrapThrowable(t);}}}}
}
3.3 其他事务等方法
以下方法都是通过LocalThread中的SqlSession进行操作的
@Overridepublic void clearCache() {final SqlSession sqlSession = localSqlSession.get();if (sqlSession == null) {throw new SqlSessionException("Error: Cannot clear the cache. No managed session is started.");}sqlSession.clearCache();}@Overridepublic void commit() {final SqlSession sqlSession = localSqlSession.get();if (sqlSession == null) {throw new SqlSessionException("Error: Cannot commit. No managed session is started.");}sqlSession.commit();}@Overridepublic void commit(boolean force) {final SqlSession sqlSession = localSqlSession.get();if (sqlSession == null) {throw new SqlSessionException("Error: Cannot commit. No managed session is started.");}sqlSession.commit(force);}@Overridepublic void rollback() {final SqlSession sqlSession = localSqlSession.get();if (sqlSession == null) {throw new SqlSessionException("Error: Cannot rollback. No managed session is started.");}sqlSession.rollback();}@Overridepublic void rollback(boolean force) {final SqlSession sqlSession = localSqlSession.get();if (sqlSession == null) {throw new SqlSessionException("Error: Cannot rollback. No managed session is started.");}sqlSession.rollback(force);}@Overridepublic List<BatchResult> flushStatements() {final SqlSession sqlSession = localSqlSession.get();if (sqlSession == null) {throw new SqlSessionException("Error: Cannot rollback. No managed session is started.");}return sqlSession.flushStatements();}@Overridepublic void close() {final SqlSession sqlSession = localSqlSession.get();if (sqlSession == null) {throw new SqlSessionException("Error: Cannot close. No managed session is started.");}try {sqlSession.close();} finally {localSqlSession.set(null);}}
总结
SqlSession的两个实现类DefaultSqlSession和SqlSessionManager.SqlSessionManager是通过DefaultSqlSession实现功能的.而DefaultSqlSession是通过内部的Executor实现的.后续章节我们再对Executor相关的代码进行详细的学习
喜欢的小伙伴请动动小手关注和点赞吧,也可留言一起探讨怎样更好的学习源码!!!
文章链接
Mybatis源码学习(一)初探执行流程
Mybatis源码学习(二)配置文件解析到SqlSessionFactory构建
Mybatis源码学习(三)SqlSession详解
Mybatis源码学习(四)自定义Mapper方法执行流程
Mybatis源码学习(五)Executor和StatementHandler详解
Mybatis源码学习(六)结果集自动封装机制
Mybatis源码学习(七)mybatis缓存详解
Mybatis源码学习(八)Mybatis设计模式总结
如若内容造成侵权/违法违规/事实不符,请联系编程学习网邮箱:809451989@qq.com进行投诉反馈,一经查实,立即删除!
相关文章
- 第三方更换通讯证书导致SSLHandshakeException
异常突现 在这普通的一天,我写普通的代码,却突然收到不普通的报警 javax.net.ssl.SSLHandshakeException: server certificate change is restrictedduring renegotiation 查看日志访问的请求全部报错,紧急联系对方,得知对方更换…...
2024/4/29 23:02:48 - jupyter notebook中使用anaconda的虚拟环境
windows下 一,需要安装ipykernel 使用conda或者pip安装都可以 conda安装命令如下 conda install ipykernelpip安装命令如下 pip install ipykernel二,将环境添加进jupyter中 python -m ipykernel install --user --name 环境名称 --display-name &q…...
2024/4/22 16:39:54 - 7、springMVC Ajax技术
文章目录1、简介1、新建一个module导入web支持!2、配置web.xml文件3、配置spring-mvc.xml文件4、编写一个controller进行测试,查看配置是否正确2、编写一个 ajax-frame.html 使用 iframe 测试,感受下效果3、jQuery.ajax(重点关注)1、编写一个…...
2024/4/29 16:43:45 - 分布式RPC系统框架Dubbo-08多协议支持
除了Dubbo服务暴露Dubbo协议外,Dubbo框架还支持另外8种服务暴露协议:RMI协议、Hessian协议、HTTP协议、WebService协议、Thrift协议、Memcached协议、Redis协议、Rest协议,但在实际生产中,使用最多的就是Dubbo服务暴露协议。 1 各个协议的特…...
2024/5/2 11:20:47 - MongoDB_如何搭建集群?
搭建步骤1.准备三台虚拟机服务器2.添加replSet配置修改mongodb.conf文件然后分别启动三台服务器:3.初始化复制集4.查看集群状态5.测试6.关闭数据库7. 主复制集添加仲裁者(arbiter)1.准备三台虚拟机服务器 各自安装好mongoDB —>技巧:可先准备配置好一…...
2024/5/2 16:10:09 - 【SSM框架入门】mybatis入门案例
在Test中创建MybatisTest类 package com.ssm.test;import com.ssm.dao.IUserDao; import com.ssm.domain.User; import org.apache.ibatis.io.Resources; import org.apache.ibatis.session.SqlSession; import org.apache.ibatis.session.SqlSessionFactory; import org.apach…...
2024/4/30 0:11:40 - LLVM简明安装教程
官网下载地址: https://releases.llvm.org/ 截止2020.9.13,最新版本为LLVM10.0.1 下载源码进行手动编译 一般情况下只需要下载LLVM source code、Clang source code、compiler-rt source code这三个文件。将其进行解压(windows下可能需要以…...
2024/4/26 1:12:04 - SuperGlue:基于图神经网络和注意力机制的特征点匹配网络
SuperGlue Background SuperGlue是Magicleap团队在SuperPoint后的又一力作,其思路与方法之巧妙不输SuperPoint,完成的任务也是传统视觉问题中特征点提取和描述(SuperPoint)的后一步–特征点匹配。 说起匹配,最传统的就…...
2024/5/2 9:40:21 - OpenStack理论学习(三)
【Neutron模块】 Neutron介绍: 虚拟化网络的实现方式: OSI七层模型: 网络命名空间(netns): 网络分类: 网络分类(二): 虚拟网络类型定义(…...
2024/4/30 15:18:43 - 力扣(重点题)
文章目录力1. 两数之和力 2. 两数相加力 3. 无重复字符的最长子串力 5. 最长回文子串力7. 整数反转力9. 回文数力14. 最长公共前缀力15. 三数之和力16. 最接近的三数之和力 18四数之和力1. 两数之和 给定一个整数数组 nums 和一个目标值 target,请你在该数组中找出…...
2024/4/29 0:54:39 - Opencv+python(五)过滤器
图像平滑处理均值滤波方框滤波高斯滤波中值滤波想要滤波的程度大一些,就需要把核的大小弄大一些;中值滤波和高斯滤波好像处理时稍好 均值滤波 任意一点的像素值,都是周围N*N给像素值的均值 5*5 的模糊程度< 10*10的模糊程度 ocv2.imrea…...
2024/4/1 17:06:39 - elementUI实现数组(需要验证的数据是以数组的形式呈现)表单验证
elementUI实现数组表单验证 <el-form :model"couponForm" ref"couponForm" label-width"200px"><el-form-item v-for"(item,idx) in couponForm.actIdList" :label"活动期间第 (idx 1) 次下单得" :prop"a…...
2024/4/29 5:00:15 - 碎片化学习Java(六)-- Java预测子女身高
本文参考 嗨客网 Java 实战 关键词: Java变量运算 Java预测子女身高案例 Java预测子女身高 题目 答案 原文 若要查看详细 解题思路、解题步骤、运行结果 原文链接:https://haicoder.net/case/java/java-variable-operator2.html 后续 大纲&#x…...
2024/4/30 4:34:21 - Netty拾遗(四)——Netty的helloworld
前言 其实前几篇博客下来,简单介绍了NIO的一些东西,可以发现NIO使用起来确实很繁琐,这也是为啥这么多人愿意选择使用Netty的重要原因之一,这一篇博客打算正式开始Netty的总结 依旧以《Netty权威指南》中的查询服务器当前时间的操…...
2024/4/29 11:24:22 - 京淘项目的完成步骤
3.5 关于JSON串说明 3.5.1 JSON介绍 JSON(JavaScript Object Notation) 是一种轻量级的数据交换格式。 易于人阅读和编写。同时也易于机器解析和生成。 3.5.2 Object对象格式 在这里插入图片描述 例子: {“id”:“1”,“name”:“tomcat猫”} 3.5.3 数组格式 在这里插入图片描…...
2024/5/2 4:21:26 - 在hive上面执行hdfs 或者Linux命令
你在hive上面要想查看 hdfs 的东西, 原本你需要再打开一个crt终端,现在不用了. hive面板查看hdfs上面的东西 直接 dfs 后面跟上命令就可以了,比如说 下面的查看hdfs 根目录下的文件有哪些 hive (default)> dfs -ls /; Found 11 items -rw-r--r-- 3 root supergroup …...
2024/5/1 14:24:39 - [内附完整源码和文档] 基于Java的电脑销售系统
摘 要 电脑管理是通过采购、仓储、综合、出库、配送等活动,解决物资供需之间存在的时间、空间、数量、品种、价格等方面的矛盾,以此衔接社会生产的各环节,从而确保生产的顺利进行。随着社会经济的发展,当企业的物流业务发展到一定…...
2024/4/30 11:15:08 - 操作系统精讲(1) | 操作系统的概念,功能,目标
目录一.操作系统的概念功能目标1.知识总览2.操作系统的定义3.操作系统功能和目标4.向上层提供方便易用的服务5.联机命令接口6.脱机命令接口7.程序接口二.操作系统的功能和目标一.操作系统的概念功能目标 1.知识总览 2.操作系统的定义 操作系统( Operating System&…...
2024/4/21 17:57:11 - JS定时器的使用
JS定时器的使用 什么是定时器? 定时器就是由JS提供了一些原生方法来实现延时去执行某一段代码。 定时器的分类 一、 第一种是一次性的: setTimeout: 设置一个定时器,在定时器到期后执行一次函数或代码段 使用方法:…...
2024/4/29 20:00:51 - 设计模式--模板模式
...
2024/4/30 5:43:51
最新文章
- 【项目纪实】某国有航空公司人力资源系统诊断咨询项目
公司的人力资源管理问题一直都比较严重,比如人员冗余、员工工作积极性差等问题,虽然经过多次的管理尝试,存在的问题仍然没有缓解。华恒智信人力资源咨询公司的老师特别专业,帮我们系统、全面的诊断了人力资源管理上存在的问题&…...
2024/5/2 20:27:42 - 梯度消失和梯度爆炸的一些处理方法
在这里是记录一下梯度消失或梯度爆炸的一些处理技巧。全当学习总结了如有错误还请留言,在此感激不尽。 权重和梯度的更新公式如下: w w − η ⋅ ∇ w w w - \eta \cdot \nabla w ww−η⋅∇w 个人通俗的理解梯度消失就是网络模型在反向求导的时候出…...
2024/3/20 10:50:27 - 【Redis】安装Redis后报ERR Client sent AUTH, but no password is set
一、问题描述 安装Redis后使用auth验证是否安装成功(或者其它应用访问redis时报错),报ERR Client sent AUTH, but no password is set 127.0.0.1:6379> auth 123456 (error) ERR Client sent AUTH, but no password is set二、问题解决 …...
2024/5/1 12:59:02 - STM32实现软件SPI对W25Q64内存芯片实现读写操作
先看看本次实验的成果吧: 这么简单的一个程序,我学习了一个星期左右,终于把所有的关节都打通了。所有代码都能什么都不看背着敲出来了。为了使自己的记忆更为清晰,特意总结了一个思维导图,感觉自己即便是日后忘记了看一…...
2024/5/1 12:08:49 - 416. 分割等和子集问题(动态规划)
题目 题解 class Solution:def canPartition(self, nums: List[int]) -> bool:# badcaseif not nums:return True# 不能被2整除if sum(nums) % 2 ! 0:return False# 状态定义:dp[i][j]表示当背包容量为j,用前i个物品是否正好可以将背包填满ÿ…...
2024/5/2 11:19:01 - 【Java】ExcelWriter自适应宽度工具类(支持中文)
工具类 import org.apache.poi.ss.usermodel.Cell; import org.apache.poi.ss.usermodel.CellType; import org.apache.poi.ss.usermodel.Row; import org.apache.poi.ss.usermodel.Sheet;/*** Excel工具类** author xiaoming* date 2023/11/17 10:40*/ public class ExcelUti…...
2024/5/2 16:04:58 - Spring cloud负载均衡@LoadBalanced LoadBalancerClient
LoadBalance vs Ribbon 由于Spring cloud2020之后移除了Ribbon,直接使用Spring Cloud LoadBalancer作为客户端负载均衡组件,我们讨论Spring负载均衡以Spring Cloud2020之后版本为主,学习Spring Cloud LoadBalance,暂不讨论Ribbon…...
2024/5/1 21:18:12 - TSINGSEE青犀AI智能分析+视频监控工业园区周界安全防范方案
一、背景需求分析 在工业产业园、化工园或生产制造园区中,周界防范意义重大,对园区的安全起到重要的作用。常规的安防方式是采用人员巡查,人力投入成本大而且效率低。周界一旦被破坏或入侵,会影响园区人员和资产安全,…...
2024/5/2 9:47:31 - VB.net WebBrowser网页元素抓取分析方法
在用WebBrowser编程实现网页操作自动化时,常要分析网页Html,例如网页在加载数据时,常会显示“系统处理中,请稍候..”,我们需要在数据加载完成后才能继续下一步操作,如何抓取这个信息的网页html元素变化&…...
2024/5/2 9:47:31 - 【Objective-C】Objective-C汇总
方法定义 参考:https://www.yiibai.com/objective_c/objective_c_functions.html Objective-C编程语言中方法定义的一般形式如下 - (return_type) method_name:( argumentType1 )argumentName1 joiningArgument2:( argumentType2 )argumentName2 ... joiningArgu…...
2024/5/2 6:03:07 - 【洛谷算法题】P5713-洛谷团队系统【入门2分支结构】
👨💻博客主页:花无缺 欢迎 点赞👍 收藏⭐ 留言📝 加关注✅! 本文由 花无缺 原创 收录于专栏 【洛谷算法题】 文章目录 【洛谷算法题】P5713-洛谷团队系统【入门2分支结构】🌏题目描述🌏输入格…...
2024/5/2 9:47:30 - 【ES6.0】- 扩展运算符(...)
【ES6.0】- 扩展运算符... 文章目录 【ES6.0】- 扩展运算符...一、概述二、拷贝数组对象三、合并操作四、参数传递五、数组去重六、字符串转字符数组七、NodeList转数组八、解构变量九、打印日志十、总结 一、概述 **扩展运算符(...)**允许一个表达式在期望多个参数࿰…...
2024/5/1 11:24:00 - 摩根看好的前智能硬件头部品牌双11交易数据极度异常!——是模式创新还是饮鸩止渴?
文 | 螳螂观察 作者 | 李燃 双11狂欢已落下帷幕,各大品牌纷纷晒出优异的成绩单,摩根士丹利投资的智能硬件头部品牌凯迪仕也不例外。然而有爆料称,在自媒体平台发布霸榜各大榜单喜讯的凯迪仕智能锁,多个平台数据都表现出极度异常…...
2024/5/2 5:31:39 - Go语言常用命令详解(二)
文章目录 前言常用命令go bug示例参数说明 go doc示例参数说明 go env示例 go fix示例 go fmt示例 go generate示例 总结写在最后 前言 接着上一篇继续介绍Go语言的常用命令 常用命令 以下是一些常用的Go命令,这些命令可以帮助您在Go开发中进行编译、测试、运行和…...
2024/5/1 20:22:59 - 用欧拉路径判断图同构推出reverse合法性:1116T4
http://cplusoj.com/d/senior/p/SS231116D 假设我们要把 a a a 变成 b b b,我们在 a i a_i ai 和 a i 1 a_{i1} ai1 之间连边, b b b 同理,则 a a a 能变成 b b b 的充要条件是两图 A , B A,B A,B 同构。 必要性显然࿰…...
2024/5/2 9:47:28 - 【NGINX--1】基础知识
1、在 Debian/Ubuntu 上安装 NGINX 在 Debian 或 Ubuntu 机器上安装 NGINX 开源版。 更新已配置源的软件包信息,并安装一些有助于配置官方 NGINX 软件包仓库的软件包: apt-get update apt install -y curl gnupg2 ca-certificates lsb-release debian-…...
2024/5/2 9:47:27 - Hive默认分割符、存储格式与数据压缩
目录 1、Hive默认分割符2、Hive存储格式3、Hive数据压缩 1、Hive默认分割符 Hive创建表时指定的行受限(ROW FORMAT)配置标准HQL为: ... ROW FORMAT DELIMITED FIELDS TERMINATED BY \u0001 COLLECTION ITEMS TERMINATED BY , MAP KEYS TERMI…...
2024/5/2 0:07:22 - 【论文阅读】MAG:一种用于航天器遥测数据中有效异常检测的新方法
文章目录 摘要1 引言2 问题描述3 拟议框架4 所提出方法的细节A.数据预处理B.变量相关分析C.MAG模型D.异常分数 5 实验A.数据集和性能指标B.实验设置与平台C.结果和比较 6 结论 摘要 异常检测是保证航天器稳定性的关键。在航天器运行过程中,传感器和控制器产生大量周…...
2024/5/2 8:37:00 - --max-old-space-size=8192报错
vue项目运行时,如果经常运行慢,崩溃停止服务,报如下错误 FATAL ERROR: CALL_AND_RETRY_LAST Allocation failed - JavaScript heap out of memory 因为在 Node 中,通过JavaScript使用内存时只能使用部分内存(64位系统&…...
2024/5/2 9:47:26 - 基于深度学习的恶意软件检测
恶意软件是指恶意软件犯罪者用来感染个人计算机或整个组织的网络的软件。 它利用目标系统漏洞,例如可以被劫持的合法软件(例如浏览器或 Web 应用程序插件)中的错误。 恶意软件渗透可能会造成灾难性的后果,包括数据被盗、勒索或网…...
2024/5/2 9:47:25 - JS原型对象prototype
让我简单的为大家介绍一下原型对象prototype吧! 使用原型实现方法共享 1.构造函数通过原型分配的函数是所有对象所 共享的。 2.JavaScript 规定,每一个构造函数都有一个 prototype 属性,指向另一个对象,所以我们也称为原型对象…...
2024/5/1 14:33:22 - C++中只能有一个实例的单例类
C中只能有一个实例的单例类 前面讨论的 President 类很不错,但存在一个缺陷:无法禁止通过实例化多个对象来创建多名总统: President One, Two, Three; 由于复制构造函数是私有的,其中每个对象都是不可复制的,但您的目…...
2024/5/2 18:46:52 - python django 小程序图书借阅源码
开发工具: PyCharm,mysql5.7,微信开发者工具 技术说明: python django html 小程序 功能介绍: 用户端: 登录注册(含授权登录) 首页显示搜索图书,轮播图࿰…...
2024/5/2 7:30:11 - 电子学会C/C++编程等级考试2022年03月(一级)真题解析
C/C++等级考试(1~8级)全部真题・点这里 第1题:双精度浮点数的输入输出 输入一个双精度浮点数,保留8位小数,输出这个浮点数。 时间限制:1000 内存限制:65536输入 只有一行,一个双精度浮点数。输出 一行,保留8位小数的浮点数。样例输入 3.1415926535798932样例输出 3.1…...
2024/5/1 20:56:20 - 配置失败还原请勿关闭计算机,电脑开机屏幕上面显示,配置失败还原更改 请勿关闭计算机 开不了机 这个问题怎么办...
解析如下:1、长按电脑电源键直至关机,然后再按一次电源健重启电脑,按F8健进入安全模式2、安全模式下进入Windows系统桌面后,按住“winR”打开运行窗口,输入“services.msc”打开服务设置3、在服务界面,选中…...
2022/11/19 21:17:18 - 错误使用 reshape要执行 RESHAPE,请勿更改元素数目。
%读入6幅图像(每一幅图像的大小是564*564) f1 imread(WashingtonDC_Band1_564.tif); subplot(3,2,1),imshow(f1); f2 imread(WashingtonDC_Band2_564.tif); subplot(3,2,2),imshow(f2); f3 imread(WashingtonDC_Band3_564.tif); subplot(3,2,3),imsho…...
2022/11/19 21:17:16 - 配置 已完成 请勿关闭计算机,win7系统关机提示“配置Windows Update已完成30%请勿关闭计算机...
win7系统关机提示“配置Windows Update已完成30%请勿关闭计算机”问题的解决方法在win7系统关机时如果有升级系统的或者其他需要会直接进入一个 等待界面,在等待界面中我们需要等待操作结束才能关机,虽然这比较麻烦,但是对系统进行配置和升级…...
2022/11/19 21:17:15 - 台式电脑显示配置100%请勿关闭计算机,“准备配置windows 请勿关闭计算机”的解决方法...
有不少用户在重装Win7系统或更新系统后会遇到“准备配置windows,请勿关闭计算机”的提示,要过很久才能进入系统,有的用户甚至几个小时也无法进入,下面就教大家这个问题的解决方法。第一种方法:我们首先在左下角的“开始…...
2022/11/19 21:17:14 - win7 正在配置 请勿关闭计算机,怎么办Win7开机显示正在配置Windows Update请勿关机...
置信有很多用户都跟小编一样遇到过这样的问题,电脑时发现开机屏幕显现“正在配置Windows Update,请勿关机”(如下图所示),而且还需求等大约5分钟才干进入系统。这是怎样回事呢?一切都是正常操作的,为什么开时机呈现“正…...
2022/11/19 21:17:13 - 准备配置windows 请勿关闭计算机 蓝屏,Win7开机总是出现提示“配置Windows请勿关机”...
Win7系统开机启动时总是出现“配置Windows请勿关机”的提示,没过几秒后电脑自动重启,每次开机都这样无法进入系统,此时碰到这种现象的用户就可以使用以下5种方法解决问题。方法一:开机按下F8,在出现的Windows高级启动选…...
2022/11/19 21:17:12 - 准备windows请勿关闭计算机要多久,windows10系统提示正在准备windows请勿关闭计算机怎么办...
有不少windows10系统用户反映说碰到这样一个情况,就是电脑提示正在准备windows请勿关闭计算机,碰到这样的问题该怎么解决呢,现在小编就给大家分享一下windows10系统提示正在准备windows请勿关闭计算机的具体第一种方法:1、2、依次…...
2022/11/19 21:17:11 - 配置 已完成 请勿关闭计算机,win7系统关机提示“配置Windows Update已完成30%请勿关闭计算机”的解决方法...
今天和大家分享一下win7系统重装了Win7旗舰版系统后,每次关机的时候桌面上都会显示一个“配置Windows Update的界面,提示请勿关闭计算机”,每次停留好几分钟才能正常关机,导致什么情况引起的呢?出现配置Windows Update…...
2022/11/19 21:17:10 - 电脑桌面一直是清理请关闭计算机,windows7一直卡在清理 请勿关闭计算机-win7清理请勿关机,win7配置更新35%不动...
只能是等着,别无他法。说是卡着如果你看硬盘灯应该在读写。如果从 Win 10 无法正常回滚,只能是考虑备份数据后重装系统了。解决来方案一:管理员运行cmd:net stop WuAuServcd %windir%ren SoftwareDistribution SDoldnet start WuA…...
2022/11/19 21:17:09 - 计算机配置更新不起,电脑提示“配置Windows Update请勿关闭计算机”怎么办?
原标题:电脑提示“配置Windows Update请勿关闭计算机”怎么办?win7系统中在开机与关闭的时候总是显示“配置windows update请勿关闭计算机”相信有不少朋友都曾遇到过一次两次还能忍但经常遇到就叫人感到心烦了遇到这种问题怎么办呢?一般的方…...
2022/11/19 21:17:08 - 计算机正在配置无法关机,关机提示 windows7 正在配置windows 请勿关闭计算机 ,然后等了一晚上也没有关掉。现在电脑无法正常关机...
关机提示 windows7 正在配置windows 请勿关闭计算机 ,然后等了一晚上也没有关掉。现在电脑无法正常关机以下文字资料是由(历史新知网www.lishixinzhi.com)小编为大家搜集整理后发布的内容,让我们赶快一起来看一下吧!关机提示 windows7 正在配…...
2022/11/19 21:17:05 - 钉钉提示请勿通过开发者调试模式_钉钉请勿通过开发者调试模式是真的吗好不好用...
钉钉请勿通过开发者调试模式是真的吗好不好用 更新时间:2020-04-20 22:24:19 浏览次数:729次 区域: 南阳 > 卧龙 列举网提醒您:为保障您的权益,请不要提前支付任何费用! 虚拟位置外设器!!轨迹模拟&虚拟位置外设神器 专业用于:钉钉,外勤365,红圈通,企业微信和…...
2022/11/19 21:17:05 - 配置失败还原请勿关闭计算机怎么办,win7系统出现“配置windows update失败 还原更改 请勿关闭计算机”,长时间没反应,无法进入系统的解决方案...
前几天班里有位学生电脑(windows 7系统)出问题了,具体表现是开机时一直停留在“配置windows update失败 还原更改 请勿关闭计算机”这个界面,长时间没反应,无法进入系统。这个问题原来帮其他同学也解决过,网上搜了不少资料&#x…...
2022/11/19 21:17:04 - 一个电脑无法关闭计算机你应该怎么办,电脑显示“清理请勿关闭计算机”怎么办?...
本文为你提供了3个有效解决电脑显示“清理请勿关闭计算机”问题的方法,并在最后教给你1种保护系统安全的好方法,一起来看看!电脑出现“清理请勿关闭计算机”在Windows 7(SP1)和Windows Server 2008 R2 SP1中,添加了1个新功能在“磁…...
2022/11/19 21:17:03 - 请勿关闭计算机还原更改要多久,电脑显示:配置windows更新失败,正在还原更改,请勿关闭计算机怎么办...
许多用户在长期不使用电脑的时候,开启电脑发现电脑显示:配置windows更新失败,正在还原更改,请勿关闭计算机。。.这要怎么办呢?下面小编就带着大家一起看看吧!如果能够正常进入系统,建议您暂时移…...
2022/11/19 21:17:02 - 还原更改请勿关闭计算机 要多久,配置windows update失败 还原更改 请勿关闭计算机,电脑开机后一直显示以...
配置windows update失败 还原更改 请勿关闭计算机,电脑开机后一直显示以以下文字资料是由(历史新知网www.lishixinzhi.com)小编为大家搜集整理后发布的内容,让我们赶快一起来看一下吧!配置windows update失败 还原更改 请勿关闭计算机&#x…...
2022/11/19 21:17:01 - 电脑配置中请勿关闭计算机怎么办,准备配置windows请勿关闭计算机一直显示怎么办【图解】...
不知道大家有没有遇到过这样的一个问题,就是我们的win7系统在关机的时候,总是喜欢显示“准备配置windows,请勿关机”这样的一个页面,没有什么大碍,但是如果一直等着的话就要两个小时甚至更久都关不了机,非常…...
2022/11/19 21:17:00 - 正在准备配置请勿关闭计算机,正在准备配置windows请勿关闭计算机时间长了解决教程...
当电脑出现正在准备配置windows请勿关闭计算机时,一般是您正对windows进行升级,但是这个要是长时间没有反应,我们不能再傻等下去了。可能是电脑出了别的问题了,来看看教程的说法。正在准备配置windows请勿关闭计算机时间长了方法一…...
2022/11/19 21:16:59 - 配置失败还原请勿关闭计算机,配置Windows Update失败,还原更改请勿关闭计算机...
我们使用电脑的过程中有时会遇到这种情况,当我们打开电脑之后,发现一直停留在一个界面:“配置Windows Update失败,还原更改请勿关闭计算机”,等了许久还是无法进入系统。如果我们遇到此类问题应该如何解决呢࿰…...
2022/11/19 21:16:58 - 如何在iPhone上关闭“请勿打扰”
Apple’s “Do Not Disturb While Driving” is a potentially lifesaving iPhone feature, but it doesn’t always turn on automatically at the appropriate time. For example, you might be a passenger in a moving car, but your iPhone may think you’re the one dri…...
2022/11/19 21:16:57