Mybatis源码(四)— 查询流程

news/2024/5/6 20:14:31/文章来源:https://blog.csdn.net/weixin_43936962/article/details/130374189

经过上一篇的getMapper方法的讲解之后getMapper解析。
此时Mybatis已经通过动态代理,创建了Dao的具体对象。因为其中MapperProxy实现了InvocationHandler,所以在执行具体的方法时,会执行MapperProxy中的invoke方法。

test方法

前几篇文章中已经解析到了getMapper方法,所以本篇会针对具体方法继续向下进行解析。

public void test02() {// 根据全局配置文件创建出SqlSessionFactoryString resource = "mybatis-config.xml";InputStream inputStream = null;try {//加载mybatis-config.xml并转换为Stream流inputStream = Resources.getResourceAsStream(resource);} catch (IOException e) {e.printStackTrace();}// SqlSessionFactory:负责创建SqlSession对象的工厂SqlSessionFactory sqlSessionFactory = new SqlSessionFactoryBuilder().build(inputStream);// SqlSession:表示跟数据库建议的一次会话// 获取数据库的会话,创建出数据库连接的会话对象(事务工厂,事务对象,执行器,如果有插件的话会进行插件的解析)SqlSession sqlSession = sqlSessionFactory.openSession();Emp empByEmpno = null;try {// 获取要调用的接口类,创建出对应的mapper的动态代理对象(mapperRegistry.knownMapper)EmpDao mapper = sqlSession.getMapper(EmpDao.class);// 调用方法开始执行empByEmpno = mapper.findEmpByEmpnoAndEname(7369, "SMITH");} catch (Exception e) {e.printStackTrace();} finally {sqlSession.close();}System.out.println(empByEmpno);}

invoke

前面已经提到,因为MapperProxy实现了InvocationHandler,所以在执行具体的方法时,会执行MapperProxy中的invoke方法。

public class MapperProxy<T> implements InvocationHandler, Serializable {private static final long serialVersionUID = -4724728412955527868L;private static final int ALLOWED_MODES = MethodHandles.Lookup.PRIVATE | MethodHandles.Lookup.PROTECTED| MethodHandles.Lookup.PACKAGE | MethodHandles.Lookup.PUBLIC;private static final Constructor<Lookup> lookupConstructor;private static final Method privateLookupInMethod;private final SqlSession sqlSession;private final Class<T> mapperInterface;//用于缓存MapperMethod对象(其中属性包含SqlCommand和MethodSignature),其中key是mapper接口中方法对应的Method对象,value是MapperMethod对象//MapperMethod对象会完成参数转换,以及SQL语句的执行功能,需要注意的是,MapperMethod中并不记录任何状态相关的信息,所以可以在多个代理对象之间共享private final Map<Method, MapperMethodInvoker> methodCache;@Overridepublic Object invoke(Object proxy, Method method, Object[] args) throws Throwable {try {//如果目标方法继承自Object,则直接调用该方法if (Object.class.equals(method.getDeclaringClass())) {return method.invoke(this, args);} else {//根据被调用接口方法的method对象,从缓存中获取MapperMethodInvoker对象,如果没有则创建一个并放入缓存,执行invoke方法。return cachedInvoker(method).invoke(proxy, method, args, sqlSession);}} catch (Throwable t) {throw ExceptionUtil.unwrapThrowable(t);}}
}
//  省略部分代码。。。。

cachedInvoker

因为是普通的接口方法,所以会执行cachedInvoker方法,将method放入methodCache缓存中。

 private MapperMethodInvoker cachedInvoker(Method method) throws Throwable {try {//如果能够在methodCache(Map<Method, MapperMethodInvoker>)中,根据method(key)找到value,则返回,找不到,就加到methodCache中//会执行ConcurrentHashMap的computeIfAbsent方法 ->// MapperProxyFactory加载时private final Map<Method, MapperMethodInvoker> methodCache = new ConcurrentHashMap<>();return MapUtil.computeIfAbsent(methodCache, method, m -> {//因为JDK1.8新特性,允许接口中有方法的具体实现(default修饰),所以在此处做判断,看要执行的方法是否是接口中的实现方法。//如果是接口中的实现方法会走下面的逻辑if (m.isDefault()) {try {if (privateLookupInMethod == null) {//根据JDK8和JDK9做了不同的操作return new DefaultMethodInvoker(getMethodHandleJava8(method));} else {return new DefaultMethodInvoker(getMethodHandleJava9(method));}} catch (IllegalAccessException | InstantiationException | InvocationTargetException| NoSuchMethodException e) {throw new RuntimeException(e);}} else {//普通的接口方法return new PlainMethodInvoker(new MapperMethod(mapperInterface, method, sqlSession.getConfiguration()));}});} catch (RuntimeException re) {Throwable cause = re.getCause();throw cause == null ? re : cause;}}

MapperMethod

如果是普通的接口方法,则先会根据mapperInterface, method和Configuration构建MapperMethod。
包含了要执行的具体sql,方法参数、返回值等。。。

 public MapperMethod(Class<?> mapperInterface, Method method, Configuration config) {this.command = new SqlCommand(config, mapperInterface, method);this.method = new MethodSignature(config, mapperInterface, method);}

SqlCommand

构造sqlCommand,根据接口名+方法名,获取MapperStatement对象,

 public SqlCommand(Configuration configuration, Class<?> mapperInterface, Method method) {//获取方法名final String methodName = method.getName();//Dao接口对象final Class<?> declaringClass = method.getDeclaringClass();MappedStatement ms = resolveMappedStatement(mapperInterface, methodName, declaringClass,configuration);//处理Flush注解if (ms == null) {if (method.getAnnotation(Flush.class) != null) {name = null;type = SqlCommandType.FLUSH;} else {throw new BindingException("Invalid bound statement (not found): "+ mapperInterface.getName() + "." + methodName);}} else {//接口全限定名+方法名name = ms.getId();//操作类型 select、insert、update。。。type = ms.getSqlCommandType();//如果type是unknown类型,抛异常if (type == SqlCommandType.UNKNOWN) {throw new BindingException("Unknown execution method for: " + name);}}}

resolveMappedStatement

 private MappedStatement resolveMappedStatement(Class<?> mapperInterface, String methodName,Class<?> declaringClass, Configuration configuration) {//接口名+方法名拼接的idString statementId = mapperInterface.getName() + "." + methodName;//因为之前解析时,MapperStatement中解析了mapper.xml所有属性节点。//configuration中的MapperStatement中是否包含当前的接口名+方法名。//所以,要想执行具体的SQL语句,就要根据statementId获取到mapperStatement对象if (configuration.hasStatement(statementId)) {return configuration.getMappedStatement(statementId);} else if (mapperInterface.equals(declaringClass)) {return null;}for (Class<?> superInterface : mapperInterface.getInterfaces()) {if (declaringClass.isAssignableFrom(superInterface)) {MappedStatement ms = resolveMappedStatement(superInterface, methodName,declaringClass, configuration);if (ms != null) {return ms;}}}return null;}

MethodSignature

类名可以翻译为方法签名,获取返回类型

public MethodSignature(Configuration configuration, Class<?> mapperInterface, Method method) {//解析方法返回值类型Type resolvedReturnType = TypeParameterResolver.resolveReturnType(method, mapperInterface);if (resolvedReturnType instanceof Class<?>) {this.returnType = (Class<?>) resolvedReturnType;} else if (resolvedReturnType instanceof ParameterizedType) {this.returnType = (Class<?>) ((ParameterizedType) resolvedReturnType).getRawType();} else {this.returnType = method.getReturnType();}//根据返回类型初始化returnsVoid、returnsMany、returnsCursor、returnsOptional等参数this.returnsVoid = void.class.equals(this.returnType);this.returnsMany = configuration.getObjectFactory().isCollection(this.returnType) || this.returnType.isArray();this.returnsCursor = Cursor.class.equals(this.returnType);this.returnsOptional = Optional.class.equals(this.returnType);// 若MethodSignature对应方法的返回值是Map且制定了@MapKey注解,则使用getMapKey方法处理this.mapKey = getMapKey(method);this.returnsMap = this.mapKey != null;// 初始化rowBoundsIndex、resultHandlerIndex字段this.rowBoundsIndex = getUniqueParamIndex(method, RowBounds.class);this.resultHandlerIndex = getUniqueParamIndex(method, ResultHandler.class);// 创建ParamNameResolver对象this.paramNameResolver = new ParamNameResolver(configuration, method);}

ParamNameResolver
参数解析、映射

public ParamNameResolver(Configuration config, Method method) {this.useActualParamName = config.isUseActualParamName();//获取参数列表中每个参数的类型final Class<?>[] paramTypes = method.getParameterTypes();//获取到注解final Annotation[][] paramAnnotations = method.getParameterAnnotations();//记录参数索引和参数名的对应关系final SortedMap<Integer, String> map = new TreeMap<>();int paramCount = paramAnnotations.length;//遍历所有注解for (int paramIndex = 0; paramIndex < paramCount; paramIndex++) {//if (isSpecialParameter(paramTypes[paramIndex])) {// skip special parameters// 如果参数是RowBounds类型或ResultHandler类型,则跳过对该参数的分析continue;}String name = null;//遍历注解for (Annotation annotation : paramAnnotations[paramIndex]) {if (annotation instanceof Param) {hasParamAnnotation = true;// 获取@Param注解指定的参数名称name = ((Param) annotation).value();break;}}if (name == null) {// @Param was not specified.// 该参数没有对应的@Param注解,则根据配置决定是否使用参数实际名称作为其名称if (useActualParamName) {name = getActualParamName(method, paramIndex);}if (name == null) {// use the parameter index as the name ("0", "1", ...)// gcode issue #71// 使用参数的索引作为其名称 arg0,arg1name = String.valueOf(map.size());}}// 记录到map中保存map.put(paramIndex, name);}// 初始化name集合names = Collections.unmodifiableSortedMap(map);}

再次回到cachedInvoker方法,因为第一次进来methodCache(Map<Method, MapperMethodInvoker>)中为该method的key为null,所以会执行上面的操作,当上面的操作执行完后,methodCache中就已经有Method的键值对了。而后,会执行MapperProxy中的invoke方法,来执行SQL的查询。

MapperProxy

public class MapperProxy<T> implements InvocationHandler, Serializable {private static class PlainMethodInvoker implements MapperMethodInvoker {private final MapperMethod mapperMethod;public PlainMethodInvoker(MapperMethod mapperMethod) {super();this.mapperMethod = mapperMethod;}//省略部分代码。。。。@Overridepublic Object invoke(Object proxy, Method method, Object[] args, SqlSession sqlSession) throws Throwable {return mapperMethod.execute(sqlSession, args);}}}

execute

根据SQL的命令类型,来执行具体的查询

public Object execute(SqlSession sqlSession, Object[] args) {Object result;//获取到SQL的操作类型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://处理返回值是Void并且ResultSet通过ResultHandler处理的方法if (method.returnsVoid() && method.hasResultHandler()) {//如果有结果处理器(ResultHandler)executeWithResultHandler(sqlSession, args);result = null;//是否返回多条记录} else if (method.returnsMany()) {result = executeForMany(sqlSession, args);//是否返回Map类型} else if (method.returnsMap()) {result = executeForMap(sqlSession, args);//返回cursor} 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;}

convertArgsToSqlCommandParam
获取到实参,并进行map映射

  public Object convertArgsToSqlCommandParam(Object[] args) {return paramNameResolver.getNamedParams(args);}
public Object getNamedParams(Object[] args) {final int paramCount = names.size();//没有参数,返回nullif (args == null || paramCount == 0) {return null;//没使用Param注解且只有一个参数} else if (!hasParamAnnotation && paramCount == 1) {Object value = args[names.firstKey()];return wrapToMapIfCollection(value, useActualParamName ? names.get(0) : null);} else {//处理使用@Param注解指定了参数名称或者多个参数final Map<String, Object> param = new ParamMap<>();int i = 0;//names是索引为key,参数名称为value的Map结构for (Map.Entry<Integer, String> entry : names.entrySet()) {//ParamMap记录了参数名称和实际参数的关系,继承了HashMap,不允许Key相同。param.put(entry.getValue(), args[entry.getKey()]);//生成param1、param2的参数形式final String genericParamName = GENERIC_NAME_PREFIX + (i + 1);// 如果names的map中,key也是以param1方式命名,则不添加,否则将param1的形式也添加到paramMap中if (!names.containsValue(genericParamName)) {param.put(genericParamName, args[entry.getKey()]);}i++;}return param;}}

selectOne
针对返回单一数据的查询

@Overridepublic <T> T selectOne(String statement, Object parameter) {// 还是调用selectList方法List<T> list = this.selectList(statement, parameter);//返回list0if (list.size() == 1) {return list.get(0);} else if (list.size() > 1) {throw new TooManyResultsException("Expected one result (or null) to be returned by selectOne(), but found: " + list.size());} else {//没有则返回nullreturn null;}}public <E> List<E> selectList(String statement, Object parameter) {//RowBounds.DEFAULT使用默认分页return this.selectList(statement, parameter, RowBounds.DEFAULT);}

selectList

private <E> List<E> selectList(String statement, Object parameter, RowBounds rowBounds, ResultHandler handler) {try {//从Configuration中获取MappedStatement,包含sql语句MappedStatement ms = configuration.getMappedStatement(statement);//使用执行器来查询结果,handler是个null//wrapCollection(parameter)获取到参数return executor.query(ms, wrapCollection(parameter), rowBounds, handler);} catch (Exception e) {throw ExceptionFactory.wrapException("Error querying database.  Cause: " + e, e);} finally {ErrorContext.instance().reset();}}

query
执行具体查询

 public <E> List<E> query(MappedStatement ms, Object parameterObject, RowBounds rowBounds, ResultHandler resultHandler) throws SQLException {//获取BoundSql对象,里面包含SQL、形参和实参BoundSql boundSql = ms.getBoundSql(parameterObject);//创建CacheKeyCacheKey key = createCacheKey(ms, parameterObject, rowBounds, boundSql);return query(ms, parameterObject, rowBounds, resultHandler, key, boundSql);}

createCacheKey
根据id、偏移量、limit等设置cacheKey

public CacheKey createCacheKey(MappedStatement ms, Object parameterObject, RowBounds rowBounds, BoundSql boundSql) {//Executor,默认SIMPLE,根据delegate创建缓存对象return delegate.createCacheKey(ms, parameterObject, rowBounds, boundSql);}public CacheKey createCacheKey(MappedStatement ms, Object parameterObject, RowBounds rowBounds, BoundSql boundSql) {//看当前Executor是否关闭if (closed) {throw new ExecutorException("Executor was closed.");}CacheKey cacheKey = new CacheKey();//将msId添加进cacheKey中 -> 接口全限定名+方法名cacheKey.update(ms.getId());cacheKey.update(rowBounds.getOffset());//将limit放到cacheKey中cacheKey.update(rowBounds.getLimit());//将sql放到cacheKey中cacheKey.update(boundSql.getSql());List<ParameterMapping> parameterMappings = boundSql.getParameterMappings();TypeHandlerRegistry typeHandlerRegistry = ms.getConfiguration().getTypeHandlerRegistry();// mimic DefaultParameterHandler logic//获取传入的实参,放到cacheKey中for (ParameterMapping parameterMapping : parameterMappings) {if (parameterMapping.getMode() != ParameterMode.OUT) {Object value;String propertyName = parameterMapping.getProperty();if (boundSql.hasAdditionalParameter(propertyName)) {value = boundSql.getAdditionalParameter(propertyName);} else if (parameterObject == null) {value = null;} else if (typeHandlerRegistry.hasTypeHandler(parameterObject.getClass())) {value = parameterObject;} else {MetaObject metaObject = configuration.newMetaObject(parameterObject);value = metaObject.getValue(propertyName);}//将实参添加到cacheKey中cacheKey.update(value);}}if (configuration.getEnvironment() != null) {// issue #176cacheKey.update(configuration.getEnvironment().getId());}return cacheKey;}

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.");}//queryStack 查询栈if (queryStack == 0 && ms.isFlushCacheRequired()) {//嵌套查询,并且select节点配置的flushCache属性为true时,才会清空一级缓存,flushCache配置项是影响一级缓存中结果对象存活时长的第一个方面clearLocalCache();}List<E> list;try {//栈++queryStack++;//查询一级缓存,key为cacheKeylist = resultHandler == null ? (List<E>) localCache.getObject(key) : null;if (list != null) {handleLocallyCachedOutputParameters(ms, key, parameter, boundSql);} else {//一级缓存为null,从数据库中查询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;}

queryFromDatabase
一级缓存为null,从数据库查询

 // 从数据库查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;}

doQuery
获取Statement对象,创建StatementHandler,调用handler执行查询

  @Overridepublic <E> List<E> doQuery(MappedStatement ms, Object parameter, RowBounds rowBounds, ResultHandler resultHandler, BoundSql boundSql) throws SQLException {Statement stmt = null;try {// 获取配置对象Configuration configuration = ms.getConfiguration();// 创建StatementHandler对象,实际返回的是RoutingStatementHandler对象StatementHandler handler = configuration.newStatementHandler(wrapper, ms, parameter, rowBounds, resultHandler, boundSql);// 完成Statement的创建和初始化stmt = prepareStatement(handler, ms.getStatementLog());// 调用query方法执行sql语句,并通过ResultSetHandler完成结果集的映射return handler.query(stmt, resultHandler);} finally {// 关闭Statement对象closeStatement(stmt);}}public <E> List<E> query(Statement statement, ResultHandler resultHandler) throws SQLException {// 获取SQL语句String sql = boundSql.getSql();// 执行SQL语句statement.execute(sql);// 映射结果集return resultSetHandler.handleResultSets(statement);}

handleResultSets
将查询后返回的结果集做映射处理

public List<Object> handleResultSets(Statement stmt) throws SQLException {ErrorContext.instance().activity("handling results").object(mappedStatement.getId());// 该集合用于保存映射结果得到的结果对象final List<Object> multipleResults = new ArrayList<>();int resultSetCount = 0;// 获取第一个ResultSet对象ResultSetWrapper rsw = getFirstResultSet(stmt);// 获取MappedStatement.resultMaps集合List<ResultMap> resultMaps = mappedStatement.getResultMaps();int resultMapCount = resultMaps.size();// 如果集合集不为空,则resultMaps集合不能为空,否则抛出异常validateResultMapsCount(rsw, resultMapCount);// 遍历resultMaps集合while (rsw != null && resultMapCount > resultSetCount) {// 获取该结果集对应的ResultMap对象ResultMap resultMap = resultMaps.get(resultSetCount);// 根据ResultMap中定义的映射规则对ResultSet进行映射,并将映射的结果对象添加到multipleResult集合中保存handleResultSet(rsw, resultMap, multipleResults, null);// 获取下一个结果集rsw = getNextResultSet(stmt);// 清空nestedResultObjects集合cleanUpAfterHandlingResultSet();// 递增resultSetCountresultSetCount++;}// 获取MappedStatement.resultSets属性,该属性对多结果集的情况使用,该属性将列出语句执行后返回的结果集,并给每个结果集一个名称,名称是逗号分隔的,String[] resultSets = mappedStatement.getResultSets();if (resultSets != null) {while (rsw != null && resultSetCount < resultSets.length) {// 根据resultSet的名称,获取未处理的ResultMappingResultMapping parentMapping = nextResultMaps.get(resultSets[resultSetCount]);if (parentMapping != null) {String nestedResultMapId = parentMapping.getNestedResultMapId();ResultMap resultMap = configuration.getResultMap(nestedResultMapId);// 根据ResultMap对象映射结果集handleResultSet(rsw, resultMap, null, parentMapping);}// 获取下一个结果集rsw = getNextResultSet(stmt);// 清空nestedResultObjects集合cleanUpAfterHandlingResultSet();// 递增resultSetCountresultSetCount++;}}return collapseSingleResultList(multipleResults);}

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.luyixian.cn/news_show_292987.aspx

如若内容造成侵权/违法违规/事实不符,请联系dt猫网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

每日一个小技巧:1招教你手机消除笔怎么用

在日常生活中&#xff0c;我们经常需要在手机上进行编辑和涂改&#xff0c;但是由于各种原因&#xff0c;我们可能会做出错误或者不满意的修改。这时候&#xff0c;消除笔就派上用场了。消除笔可以帮助我们在不影响其他内容的前提下&#xff0c;对错误或者不满意的修改进行撤销…

机器学习笔记Python笔记:HMM(隐马尔科夫模型)

1 引子&#xff1a;猜天气小游戏 一对异地恋的情侣&#xff0c;女朋友想根据男友的心情猜测男友所在城市的天气 1.1 天气和心情一定一一对应 晴天——>高兴雨天——>烦躁 可以根据心情唯一确定天气 1.2 天气和心情没有一一对应 晴天——>80%高兴&#xff0c;20%烦…

Django项目之经济预测平台,应用LSTM、GBDT等算法

一、平台功能与技术点 1.技术点&#xff1a;Python3.9、Django4.1.7&#xff0c; tensorflow2.11.0&#xff0c;keras2.11.0&#xff0c;numpy1.24.2、bootstrap、ajax、MySQL等等 2.功能&#xff1a;正常前后端&#xff0c;前台主要完成经济预测功能&#xff08;特征和标签都…

vue2数据响应式原理(7) 收集依赖,用get和set叙述出最基础的至高vue哲学

收集依赖在整个数据响应式中算是比较难的 首先 要理解这里所指的依赖 依赖 可能vue项目做多了就会想到 npm i 但其实跟这个是没有什么关系的 我们这里所指的依赖 是用到数据的地方 什么地方用到数据 什么地方就是依赖 简单说 就是依赖这个响应式数据 首先 我们看一下 vue1 和…

PWM 呼吸灯实验

PWM 呼吸灯实验 FPGA实现一个PWM模块&#xff08;硬件&#xff09;来控制灯的亮灭。 实验原理 PWM本质上就是一个输出脉冲的硬件&#xff0c;通过改变一个周期高电平&#xff08;占空比&#xff09;的时间来对其他的硬件进行控制&#xff0c;比如电机。 呼吸灯的实现利用了人…

ChatGPT实现语义分析情感分类

语义分析情感分类 我们从开源社区找到了中科院谭松波博士整理的携程网酒店评论数据集(https://raw.githubusercontent.com/SophonPlus/ChineseNlpCorpus/master/datasets/ChnSentiCorp_htl_all/ChnSentiCorp_htl_all.csv)。一共七千余条数据&#xff0c;包括 label 和 review …

vue封装公共组件库并发布到npm库详细教程

vue组件封装的原理&#xff1a;利用vue框架提供的api: Vue.use( plugin )&#xff0c;我们需要把封装好组件的项目打包成vue库&#xff0c;并提供install方法&#xff0c;然后发布到npm中。Vue.use( plugin )的时候会自动执行插件中的install方法。 一、组件库代码目录 目录…

【Python_Opencv图像处理框架】边缘检测、轮廓检测、图像金字塔

写在前面 本篇文章是opencv学习的第四篇文章&#xff0c;主要讲解了边缘及轮廓检测的主要操作&#xff0c;并对两种图像金字塔简单的介绍了一下&#xff0c;作为初学者&#xff0c;我尽己所能&#xff0c;但仍会存在疏漏的地方&#xff0c;希望各位看官不吝指正&#x1f60d; …

C语言 sizeof, size_t, strlen

C语言 sizeof, size_t, strlen 文章目录 C语言 sizeof, size_t, strlen一. sizeof1.1 返回结构体长度 二. size_t三. sizeof 和 strlen 一. sizeof 返回一个结构体或者类型所占的内存字节数 1.1 返回结构体长度 这里我编写了2个结构体&#xff0c;区别在于数组问题 #include …

基于本地知识构建简易的chatPDF

Langchain chatglm-6b 文章目录 Langchain chatglm-6b前言一、实验记录1.1 环境配置1.2 代码理解1.3 补充内容 二、总结 前言 介绍&#xff1a;一种利用 ChatGLM-6B langchain 实现的基于本地知识的 ChatGLM 应用 Github: https://github.com/imClumsyPanda/langchain-Chat…

《个人博客部署上线教程一》Halo搭建个人博客网站

Halo搭建个人博客网站 一、docker部署Halo 目前测试了两种方法安装Halo&#xff0c;第一种是使用Jar包安装:提供JAR包资源&#xff0c;不过因为使用jar包部署需要Java11才可以&#xff0c;我本机使用的是Java8&#xff0c;所以暂时不做调整。第二种是通过docker安装。 1.1 启…

if条件语句

if条件语句 条件测试 test 测试表达式是否成立&#xff0c;若成立返回0&#xff0c;否则返回其他数值 格式1 &#xff1a;test 条件表达式&#xff1b;格式2 &#xff1a;[ 条件表达式 ] echo $?参数作用-d测试是否为目录 (Directory)-e测试目录或文件是否存在(Exist)-f测…

【java笔记】java多线程

目录 一、概念 1.1 什么是进程&#xff1f; 1.2 什么是线程&#xff1f; 1.3 什么事多线程&#xff1f; 1.4 进程和线程的关系 二、线程对象的生命周期 三、实现线程有两种方式 3.1 继承 java.lang.Thread&#xff0c;重写 run方法 3.2 实现 java.lang.Runnable 接口…

八、vue_options之computed、watch属性选项

一、computed计算属性使用 &#xff08;1&#xff09;复杂data的处理方式 &#xff08;2&#xff09;computed 计算属性 computed计算属性初体验&#xff1a; 在我们通过Vue调用createApp方法传入一个对象的时候&#xff0c;我们之前写了data属性、methods属性&#xff0c;这…

HTB-Time

HTB-Time 信息收集80端口 立足pericles -> root 信息收集 80端口 有两个功能&#xff0c;一个是美化JSON数据。 一个是验证JSON&#xff0c;并且输入{“abc”:“abc”}之类的会出现报错。 Validation failed: Unhandled Java exception: com.fasterxml.jackson.core.JsonPa…

低代码是开发的未来,还是只能解决边角问题的鸡肋?

随着互联网行业寒冬期的到来&#xff0c;降本增效、开源节流几乎成为了全球互联网厂商共同的应对措施&#xff0c;甚至高薪酬程序员的“35岁危机”一下子似乎变成了现实。程序员的高薪吸引了各行各业的“跨界选手”&#xff0c;是编程门槛降低了吗&#xff1f;不全是&#xff0…

Linux Ansible管理变量、管理事实、管理机密

目录 Ansible变量 变量定义范围 变量类型 定义变量并引用 事实变量与魔法变量 事实变量 魔法变量 Ansible加密 ansible-vault参数 ansible-vault举例 Ansible变量 Ansible支持利用变量来存储值&#xff0c;并且可以在Ansible项目的所有文件中重复使用这些值 变量可能…

Hadoop3.2.4+Hive3.1.2+sqoop1.4.7安装部署

目录 一、软件包 二、JDK部署 1.JDK解压 2.设置环境变量 3.环境验证 4.分发JDK相关文件至Node_02、Node_03 5.环境生效 三、Zookeeper部署 1.Zookeeper解压 2.Zookeeper配置 3.创建myid文件 4.设置环境变量并添加映射 5.分发ZooKeeper 相关文件至Node_02、Node_0…

Qt — Graphics/View框架

文章目录 前言一、Qt图形系统介绍二、Graphics/View框架 前言 Qt的Graphics/View框架被用来存放、显示二维图形元素&#xff0c;处理那些对图形元素进行操作的交互命令。 一、Qt图形系统介绍 Qt 应用程序的图形界面包含各种控件&#xff0c;比如窗口、按钮、滚动条等。所有这…

【单目标优化算法】沙猫群优化算法(Matlab代码实现)

&#x1f4a5;&#x1f4a5;&#x1f49e;&#x1f49e;欢迎来到本博客❤️❤️&#x1f4a5;&#x1f4a5; &#x1f3c6;博主优势&#xff1a;&#x1f31e;&#x1f31e;&#x1f31e;博客内容尽量做到思维缜密&#xff0c;逻辑清晰&#xff0c;为了方便读者。 ⛳️座右铭&a…