【源码】Spring AOP 4 Pointcut
【源码】Spring AOP 4 Pointcut
- 前言
- 接口
- Pointcut
- ClassFilter
- AnnotationClassFilter
- MethodMatcher
- DynamicMethodMatcher
- DynamicMethodMatcherPointcut
- IntroductionAwareMethodMatcher
- StaticMethodMatcher
- AnnotationMethodMatcher
- StaticMethodMatcherPointcut
- NameMatchMethodPointcut
- AbstractRegexpMethodPointcut
- JdkRegexpMethodPointcut
- Pointcut
- ComposablePointcut
- AnnotationMatchingPointcut
- ExpressionPointcut
- AbstractExpressionPointcut
- AspectJExpressionPointcut
- 类图
- Pointcut
- ClassFilter
- MethodMatcher
- 总结
- 参考:
前言
Spring AOP 同样也定义好几大族接口,以辅助 AOP 的实现,这章节我们来解析 Pointcut 接口。Pointcut ,切点。它是对 Joinpoint 的匹配点的抽象,可以理解为 Advice 通过 Pointcut 找到 Joinpoint
接口
Pointcut
public interface Pointcut {// 类匹配ClassFilter getClassFilter();// 方法匹配MethodMatcher getMethodMatcher();// 匹配所有 Pointcut Pointcut TRUE = TruePointcut.INSTANCE;}
Pointcut 提供 ClassFilter 和 MethodMatcher 获取,事实上,它们可以组合使用
先来分别介绍 ClassFilter 和 MethodMatcher
ClassFilter
@FunctionalInterface
public interface ClassFilter {// 给定类是否匹配boolean matches(Class<?> clazz);// 匹配所有类ClassFilter TRUE = TrueClassFilter.INSTANCE;}
其子类需要重写 equals(Object)
和 hashCode()
方法
看一个实现类体会一下
AnnotationClassFilter
基于注解匹配类
// 检查给定类是否包含指定注解
public class AnnotationClassFilter implements ClassFilter {private final Class<? extends Annotation> annotationType;// 是否检查内部类private final boolean checkInherited;public AnnotationClassFilter(Class<? extends Annotation> annotationType) {this(annotationType, false);}public AnnotationClassFilter(Class<? extends Annotation> annotationType, boolean checkInherited) {Assert.notNull(annotationType, "Annotation type must not be null");this.annotationType = annotationType;this.checkInherited = checkInherited;}@Overridepublic boolean matches(Class<?> clazz) {return (this.checkInherited ? AnnotatedElementUtils.hasAnnotation(clazz, this.annotationType) :clazz.isAnnotationPresent(this.annotationType));}// hashCode equals toString 略}
MethodMatcher
public interface MethodMatcher {// 静态匹配boolean matches(Method method, Class<?> targetClass);// true 动态 false 静态boolean isRuntime();// 动态匹配boolean matches(Method method, Class<?> targetClass, Object... args);// 匹配所有方法MethodMatcher TRUE = TrueMethodMatcher.INSTANCE;}
静态匹配:不会对方法的参数进行匹配
动态匹配:会同时匹配方法的参数,不常用
看看它的实现类
DynamicMethodMatcher
public abstract class DynamicMethodMatcher implements MethodMatcher {@Overridepublic final boolean isRuntime() {return true;}@Overridepublic boolean matches(Method method, Class<?> targetClass) {return true;}
}
动态匹配抽象类,isRuntime()
和 matches(Method method, Class<?> targetClass)
都返回 true
DynamicMethodMatcherPointcut
public abstract class DynamicMethodMatcherPointcut extends DynamicMethodMatcher implements Pointcut {// 匹配所有类@Overridepublic ClassFilter getClassFilter() {return ClassFilter.TRUE;}@Overridepublic final MethodMatcher getMethodMatcher() {return this;}}
动态 MethodMatcher 和 Pointcut 的组合
IntroductionAwareMethodMatcher
public interface IntroductionAwareMethodMatcher extends MethodMatcher {// 若实现该接口,用该方法代替静态匹配方法boolean matches(Method method, Class<?> targetClass, boolean hasIntroductions);}
AspectJExpressionPointcut 实现了该接口,下边有介绍
StaticMethodMatcher
public abstract class StaticMethodMatcher implements MethodMatcher {@Overridepublic final boolean isRuntime() {return false;}@Overridepublic final boolean matches(Method method, Class<?> targetClass, Object... args) {throw new UnsupportedOperationException("Illegal MethodMatcher usage");}}
静态匹配的抽象类,故 isRuntime
为 false ,动态匹配方法抛出 UnsupportedOperationException
异常
AnnotationMethodMatcher
基于注解匹配方法
public class AnnotationMethodMatcher extends StaticMethodMatcher {private final Class<? extends Annotation> annotationType;private final boolean checkInherited;public AnnotationMethodMatcher(Class<? extends Annotation> annotationType) {this(annotationType, false);}public AnnotationMethodMatcher(Class<? extends Annotation> annotationType, boolean checkInherited) {Assert.notNull(annotationType, "Annotation type must not be null");this.annotationType = annotationType;this.checkInherited = checkInherited;}@Overridepublic boolean matches(Method method, Class<?> targetClass) {if (matchesMethod(method)) {return true;}// 目标类是否代理类if (Proxy.isProxyClass(targetClass)) {return false;}// 如果是接口方法,还会检查实现类Method specificMethod = AopUtils.getMostSpecificMethod(method, targetClass);return (specificMethod != method && matchesMethod(specificMethod));}// 根据 checkInherited 区分是否需要检查父类方法private boolean matchesMethod(Method method) {return (this.checkInherited ? AnnotatedElementUtils.hasAnnotation(method, this.annotationType) :method.isAnnotationPresent(this.annotationType));}// 其他方法略}
StaticMethodMatcherPointcut
public abstract class StaticMethodMatcherPointcut extends StaticMethodMatcher implements Pointcut {private ClassFilter classFilter = ClassFilter.TRUE;public void setClassFilter(ClassFilter classFilter) {this.classFilter = classFilter;}@Overridepublic ClassFilter getClassFilter() {return this.classFilter;}@Overridepublic final MethodMatcher getMethodMatcher() {return this;}}
静态 MethodMatcher 和 Pointcut 的组合。支持传入自定义的 ClassFilter ,默认 ClassFilter.TRUE
NameMatchMethodPointcut
public class NameMatchMethodPointcut extends StaticMethodMatcherPointcut implements Serializable {// 匹配模板private List<String> mappedNames = new ArrayList<>();public void setMappedName(String mappedName) {setMappedNames(mappedName);}public void setMappedNames(String... mappedNames) {this.mappedNames = new ArrayList<>(Arrays.asList(mappedNames));}// 添加模板方法public NameMatchMethodPointcut addMethodName(String name) {this.mappedNames.add(name);return this;}// 静态匹配,equals 或者正则匹配@Overridepublic boolean matches(Method method, Class<?> targetClass) {for (String mappedName : this.mappedNames) {if (mappedName.equals(method.getName()) || isMatch(method.getName(), mappedName)) {return true;}}return false;}// 支持形如 "xxx*", "*xxx" 的正则匹配protected boolean isMatch(String methodName, String mappedName) {return PatternMatchUtils.simpleMatch(mappedName, methodName);}// 略
}
基于方法名匹配,同时支持形如 “xxx*”, "*xxx"的模糊匹配,比如*Service
匹配所有 Serivce 结尾的方法。
看个 demo
@My
public class A {public void aaa() {}public void bbb() {}
}public class B {public void aaa() {}
}public class NameMatchMethodTest {public static void main(String[] args) {NameMatchMethodPointcut matchMethodPointcut= new NameMatchMethodPointcut();matchMethodPointcut.setClassFilter(new AnnotationClassFilter(My.class));matchMethodPointcut.setMappedName("*a");if (matchMethodPointcut.getClassFilter().matches(A.class)) {for (Method m : A.class.getDeclaredMethods()) {boolean match = matchMethodPointcut.matches(m, A.class);System.out.println("A类的方法" + m.getName() + (match ? " 匹配" : " 不匹配"));}} else {System.out.println("A类不匹配");}if (matchMethodPointcut.getClassFilter().matches(B.class)) {for (Method m : B.class.getDeclaredMethods()) {boolean match = matchMethodPointcut.matches(m, B.class);System.out.println("B类的方法" + m.getName() + (match ? " 匹配" : " 不匹配"));}} else {System.out.println("B类不匹配");}}
}// 结果
A类的方法aaa 匹配
A类的方法bbb 不匹配
B类不匹配
AbstractRegexpMethodPointcut
正则匹配的抽象类。模板方法设计模式,将匹配方法抽象出来由子类 (JdkRegexpMethodPointcut) 实现。
public abstract class AbstractRegexpMethodPointcut extends StaticMethodMatcherPointcutimplements Serializable {// 匹配正则private String[] patterns = new String[0];// 排除正则private String[] excludedPatterns = new String[0];public void setPattern(String pattern) {setPatterns(pattern);}public void setPatterns(String... patterns) {Assert.notEmpty(patterns, "'patterns' must not be empty");this.patterns = new String[patterns.length];for (int i = 0; i < patterns.length; i++) {this.patterns[i] = StringUtils.trimWhitespace(patterns[i]);}initPatternRepresentation(this.patterns);}public String[] getPatterns() {return this.patterns;}public void setExcludedPattern(String excludedPattern) {setExcludedPatterns(excludedPattern);}public void setExcludedPatterns(String... excludedPatterns) {Assert.notEmpty(excludedPatterns, "'excludedPatterns' must not be empty");this.excludedPatterns = new String[excludedPatterns.length];for (int i = 0; i < excludedPatterns.length; i++) {this.excludedPatterns[i] = StringUtils.trimWhitespace(excludedPatterns[i]);}initExcludedPatternRepresentation(this.excludedPatterns);}public String[] getExcludedPatterns() {return this.excludedPatterns;}// 匹配方法,给定类找不到回去该方法的当前类找@Overridepublic boolean matches(Method method, Class<?> targetClass) {return (matchesPattern(ClassUtils.getQualifiedMethodName(method, targetClass)) ||(targetClass != method.getDeclaringClass() &&matchesPattern(ClassUtils.getQualifiedMethodName(method, method.getDeclaringClass()))));}// 匹配与排除protected boolean matchesPattern(String signatureString) {for (int i = 0; i < this.patterns.length; i++) {boolean matched = matches(signatureString, i);if (matched) {for (int j = 0; j < this.excludedPatterns.length; j++) {boolean excluded = matchesExclusion(signatureString, j);if (excluded) {return false;}}return true;}}return false;}// 模板方法,初始化匹配正则protected abstract void initPatternRepresentation(String[] patterns) throws IllegalArgumentException;// 模板方法,初始化排除正则protected abstract void initExcludedPatternRepresentation(String[] patterns) throws IllegalArgumentException;// 模板方法,正则匹配protected abstract boolean matches(String pattern, int patternIndex);// 模板方法,排除正则匹配protected abstract boolean matchesExclusion(String pattern, int patternIndex);// 略}
JdkRegexpMethodPointcut
实现类,方法清晰明了,Pattern 类解析匹配正则。
public class JdkRegexpMethodPointcut extends AbstractRegexpMethodPointcut {private Pattern[] compiledPatterns = new Pattern[0];private Pattern[] compiledExclusionPatterns = new Pattern[0];@Overrideprotected void initPatternRepresentation(String[] patterns) throws PatternSyntaxException {this.compiledPatterns = compilePatterns(patterns);}@Overrideprotected void initExcludedPatternRepresentation(String[] excludedPatterns) throws PatternSyntaxException {this.compiledExclusionPatterns = compilePatterns(excludedPatterns);}@Overrideprotected boolean matches(String pattern, int patternIndex) {Matcher matcher = this.compiledPatterns[patternIndex].matcher(pattern);return matcher.matches();}@Overrideprotected boolean matchesExclusion(String candidate, int patternIndex) {Matcher matcher = this.compiledExclusionPatterns[patternIndex].matcher(candidate);return matcher.matches();}private Pattern[] compilePatterns(String[] source) throws PatternSyntaxException {Pattern[] destination = new Pattern[source.length];for (int i = 0; i < source.length; i++) {destination[i] = Pattern.compile(source[i]);}return destination;}
}
看看 demo
public class A {public void aaa111() {}public void aaabb() {}public void bbb() {}
}public class JdkRegrexpMthodTest {public static void main(String[] args) {JdkRegexpMethodPointcut jdkRegexpMethodPointcut= new JdkRegexpMethodPointcut();jdkRegexpMethodPointcut.setPattern(".*a+.+$");jdkRegexpMethodPointcut.setExcludedPattern(".*a+\\d+$");for (Method m : A.class.getDeclaredMethods()) {boolean match = jdkRegexpMethodPointcut.matches(m, A.class);System.out.println("A类的方法" + m.getName() + (match ? " 匹配" : " 不匹配"));}}
}// 结果
A类的方法aaa111 不匹配
A类的方法bbb 不匹配
A类的方法aaabb 匹配
Pointcut
对 MethodMatcher 和 ClassFilter 的接口和部分实现类做了了解之后,回头再来看看 Pointcut 下的几个实现类
ComposablePointcut
public class ComposablePointcut implements Pointcut, Serializable {private static final long serialVersionUID = -2743223737633663832L;private ClassFilter classFilter;private MethodMatcher methodMatcher;public ComposablePointcut() {this.classFilter = ClassFilter.TRUE;this.methodMatcher = MethodMatcher.TRUE;}public ComposablePointcut(Pointcut pointcut) {Assert.notNull(pointcut, "Pointcut must not be null");this.classFilter = pointcut.getClassFilter();this.methodMatcher = pointcut.getMethodMatcher();}public ComposablePointcut(ClassFilter classFilter) {Assert.notNull(classFilter, "ClassFilter must not be null");this.classFilter = classFilter;this.methodMatcher = MethodMatcher.TRUE;}public ComposablePointcut(MethodMatcher methodMatcher) {Assert.notNull(methodMatcher, "MethodMatcher must not be null");this.classFilter = ClassFilter.TRUE;this.methodMatcher = methodMatcher;}public ComposablePointcut(ClassFilter classFilter, MethodMatcher methodMatcher) {Assert.notNull(classFilter, "ClassFilter must not be null");Assert.notNull(methodMatcher, "MethodMatcher must not be null");this.classFilter = classFilter;this.methodMatcher = methodMatcher;}// 借助 ClassFilters 合并 ClassFilterpublic ComposablePointcut union(ClassFilter other) {this.classFilter = ClassFilters.union(this.classFilter, other);return this;}// 借助 ClassFilters 取 ClassFilter 交集public ComposablePointcut intersection(ClassFilter other) {this.classFilter = ClassFilters.intersection(this.classFilter, other);return this;}// 借助 ClassFilters 合并 MethodMatcherpublic ComposablePointcut union(MethodMatcher other) {this.methodMatcher = MethodMatchers.union(this.methodMatcher, other);return this;}// 借助 ClassFilters 取 MethodMatcher 交集public ComposablePointcut intersection(MethodMatcher other) {this.methodMatcher = MethodMatchers.intersection(this.methodMatcher, other);return this;}// 借助 ClassFilters 分别合并给定 Pointcut 的 methodMatcher 和 classFilterpublic ComposablePointcut union(Pointcut other) {this.methodMatcher = MethodMatchers.union(this.methodMatcher, this.classFilter, other.getMethodMatcher(), other.getClassFilter());this.classFilter = ClassFilters.union(this.classFilter, other.getClassFilter());return this;}// 借助 ClassFilters 做给定 Pointcut 的 methodMatcher 和 classFilter 的交集public ComposablePointcut intersection(Pointcut other) {this.classFilter = ClassFilters.intersection(this.classFilter, other.getClassFilter());this.methodMatcher = MethodMatchers.intersection(this.methodMatcher, other.getMethodMatcher());return this;}@Overridepublic ClassFilter getClassFilter() {return this.classFilter;}@Overridepublic MethodMatcher getMethodMatcher() {return this.methodMatcher;}// 略}
组合实现类,包含各种对 ClassFilter,MethodMatcher 和 Pointcut 的组合操作
AnnotationMatchingPointcut
public class AnnotationMatchingPointcut implements Pointcut {private final ClassFilter classFilter;private final MethodMatcher methodMatcher;public AnnotationMatchingPointcut(Class<? extends Annotation> classAnnotationType) {this(classAnnotationType, false);}// 构造 ClassFilterpublic AnnotationMatchingPointcut(Class<? extends Annotation> classAnnotationType, boolean checkInherited) {this.classFilter = new AnnotationClassFilter(classAnnotationType, checkInherited);this.methodMatcher = MethodMatcher.TRUE;}public AnnotationMatchingPointcut(@Nullable Class<? extends Annotation> classAnnotationType,@Nullable Class<? extends Annotation> methodAnnotationType) {this(classAnnotationType, methodAnnotationType, false);}public AnnotationMatchingPointcut(@Nullable Class<? extends Annotation> classAnnotationType,@Nullable Class<? extends Annotation> methodAnnotationType, boolean checkInherited) {// classAnnotationType 为 null 则以 methodAnnotationType 构造 AnnotationCandidateClassFilterif (classAnnotationType != null) {this.classFilter = new AnnotationClassFilter(classAnnotationType, checkInherited);}else {this.classFilter = new AnnotationCandidateClassFilter(methodAnnotationType);}// 构造 MethodMatcherif (methodAnnotationType != null) {this.methodMatcher = new AnnotationMethodMatcher(methodAnnotationType, checkInherited);}else {this.methodMatcher = MethodMatcher.TRUE;}}// 略// 传入的类注解为空时构造此 ClassFilterpublic static AnnotationMatchingPointcut forClassAnnotation(Class<? extends Annotation> annotationType) {Assert.notNull(annotationType, "Annotation type must not be null");return new AnnotationMatchingPointcut(annotationType);}public static AnnotationMatchingPointcut forMethodAnnotation(Class<? extends Annotation> annotationType) {Assert.notNull(annotationType, "Annotation type must not be null");return new AnnotationMatchingPointcut(null, annotationType);}private static class AnnotationCandidateClassFilter implements ClassFilter {private final Class<? extends Annotation> annotationType;AnnotationCandidateClassFilter(Class<? extends Annotation> annotationType) {this.annotationType = annotationType;}@Overridepublic boolean matches(Class<?> clazz) {return AnnotationUtils.isCandidateClass(clazz, this.annotationType);}// 略}
}
注解匹配的 Pointcut,可以理解为上面介绍的 AnnotationClassFilter 和 AnnotationMethodMatcher 的组合。
ExpressionPointcut
public interface ExpressionPointcut extends Pointcut {// 表达式获取@NullableString getExpression();}
表达式(其实就是 AspectJ 表达式嘛)匹配的接口
AbstractExpressionPointcut
public abstract class AbstractExpressionPointcut implements ExpressionPointcut, Serializable {@Nullableprivate String location;@Nullableprivate String expression;public void setLocation(@Nullable String location) {this.location = location;}@Nullablepublic String getLocation() {return this.location;}public void setExpression(@Nullable String expression) {this.expression = expression;try {onSetExpression(expression);}catch (IllegalArgumentException ex) {// ...}}// 允许子类拓展protected void onSetExpression(@Nullable String expression) throws IllegalArgumentException {}@Override@Nullablepublic String getExpression() {return this.expression;}}
表达式匹配 Pointcut 的抽象类,提供表达式位置信息和相关操作,提供一个模板方法 onSetExpression
供子类实现。
AspectJExpressionPointcut
很关键的一个类,对 Aspect 切点表达式匹配的实现。
它是 Pointcut, ClassFilter 和 MethodMatcher 的组合, 同时实现了 BeanFactoryAware(可以跟 bean工厂 互动)
public class AspectJExpressionPointcut extends AbstractExpressionPointcutimplements ClassFilter, IntroductionAwareMethodMatcher, BeanFactoryAware
它支持如下 AspectJ 原语
static {SUPPORTED_PRIMITIVES.add(PointcutPrimitive.EXECUTION);SUPPORTED_PRIMITIVES.add(PointcutPrimitive.ARGS);SUPPORTED_PRIMITIVES.add(PointcutPrimitive.REFERENCE);SUPPORTED_PRIMITIVES.add(PointcutPrimitive.THIS);SUPPORTED_PRIMITIVES.add(PointcutPrimitive.TARGET);SUPPORTED_PRIMITIVES.add(PointcutPrimitive.WITHIN);SUPPORTED_PRIMITIVES.add(PointcutPrimitive.AT_ANNOTATION);SUPPORTED_PRIMITIVES.add(PointcutPrimitive.AT_WITHIN);SUPPORTED_PRIMITIVES.add(PointcutPrimitive.AT_ARGS);SUPPORTED_PRIMITIVES.add(PointcutPrimitive.AT_TARGET);}
我们最常用的应该就是 execution
了
事实上,最终对表达式的解析和匹配还是委托给 AspectJ 的相关类来实现的
import org.aspectj.weaver.patterns.NamePattern;
import org.aspectj.weaver.reflect.ReflectionWorld.ReflectionWorldException;
import org.aspectj.weaver.reflect.ShadowMatchImpl;
import org.aspectj.weaver.tools.ContextBasedMatcher;
import org.aspectj.weaver.tools.FuzzyBoolean;
import org.aspectj.weaver.tools.JoinPointMatch;
import org.aspectj.weaver.tools.MatchingContext;
import org.aspectj.weaver.tools.PointcutDesignatorHandler;
import org.aspectj.weaver.tools.PointcutExpression;
import org.aspectj.weaver.tools.PointcutParameter;
import org.aspectj.weaver.tools.PointcutParser;
import org.aspectj.weaver.tools.PointcutPrimitive;
import org.aspectj.weaver.tools.ShadowMatch;
具体方法就不一一解读了。写个 demo 体验一下
public class AService implements A {public void a() {}
}public class BService implements B {public void b() {}
}public class Test2 {@Testpublic void test1() {AspectJExpressionPointcut aspectJExpressionPointcut= new AspectJExpressionPointcut();aspectJExpressionPointcut.setExpression("execution(* a())");System.out.println("A类:" + aspectJExpressionPointcut.matches(AService.class));System.out.println("B类:" + aspectJExpressionPointcut.matches(BService.class));System.out.println("================================");for (Method m : AService.class.getDeclaredMethods()) {System.out.println(m.getName() + ": " +aspectJExpressionPointcut.matches(m, m.getDeclaringClass()));}System.out.println("================================");for (Method m : BService.class.getDeclaredMethods()) {System.out.println(m.getName() + ": " +aspectJExpressionPointcut.matches(m, m.getDeclaringClass()));}}
}// 结果
A类:true
B类:true
================================
a: true
================================
b: false
类图
Pointcut
ClassFilter
MethodMatcher
总结
这一章节涉及的类比较多一点,主要对 Pointcut 体系抽象做了整体的了解,它可以与 ClassFilter 和 MethodMatcher 组合,来实现对类、方法的匹配。其中 AspectJExpressionPointcut 就是对基于注解的 AspectJ 的 切点表达式 的匹配实现。下一章节,我们再对 Spring 下的 Advisor 抽象进行解读。
上一篇:【源码】Spring AOP 3 Joinpoint
下一篇:【源码】Spring AOP 5 Advisor
参考:
【小家Spring】Spring AOP核心类Pointcut解析,对PointcutExpression切点表达式解析原理分析(以AspectJExpressionPointcut为例)
如若内容造成侵权/违法违规/事实不符,请联系编程学习网邮箱:809451989@qq.com进行投诉反馈,一经查实,立即删除!
相关文章
- Hopcroft-Karp算法 poj-1469 COURSES
Hopcroft-karp算法 该算法由John.E.Hopcroft和Richard M.Karp于1973提出,故称Hopcroft-Karp算法。 使用情形 给定一个二分图,求其最大匹配。 原理简述 在增广匹配集时,每次寻找多条增广路径,以进一步减少时间复杂度。 步骤及示例演示 dx【】、dy【】 分别表示二分图左右不顶…...
2024/4/29 1:06:49 - JQuery的快速入门
JQuery的快速入门 JQuery的诞生背景: 为了简化 JavaScript 的开发,一些 JavsScript 库诞生了。 JQuery的本质: jQuery库实际上就是一个js文件,只需要在网页中直接引入这个文件就可以了。 需求:使用jQuery给一个按钮绑定单击事件 <!-- 导入jQuery库--> <script ty…...
2024/4/29 1:06:46 - Lock对象
Lock锁对象 1、创建锁对象 Lock l = new ReentrantLock;2、Lock锁对象释放锁需要手动释放,遇到异常也不会自动释放。所以一般会放在finally之中。 3、示例 Lock lock = new ReentrantLock; m(){lock.lock();.......finally{lock.unlock();} }4、tryLock尝试锁 tryLock是尝试进…...
2024/4/30 1:21:18 - MySql Schema与数据类型优化
一、数据类型的选择原则更小的通常更好1.更小的数据类型通常更快,因为它们占用更少的磁盘、内存和CPU缓存,并且处理时需要的CPU周期也更少。2.要确保没有低估需要存储值得范围,因为在schema中的多个地方增加数据类型的范围是一个非常耗时和痛苦的操作。如果无法确定哪个类型…...
2024/4/30 1:21:21 - C++向上向下类型转换的安全性问题
向上类型转换是指子类对象转为父类对象,向下类型转换是指父类对象转换为子类对象。(父辈在上)如果没有发生多态(父类指针指向子类对象),那么向下转换是不安全的,向上转换是安全的。Animal* anim = new Animal;基类转派生类Cat* cat = (Cat*)anim;这样是不安全的,因为Ca…...
2024/4/30 1:21:16 - PHP服务-MySQL图形界面的安装及简单使用
一、安装Apache和mariadb服务1.安装、配置、开启服务2.关闭火墙3.网络配置完成 #172.254.25.10二、安装PHP服务软件及MySQL的插件1.安装PHP服务软件及MySQL的插件dnf install php -y #安装PHP服务 dnf install php-mysqlnd.x86_64 -y #安装PHP中M…...
2024/4/30 1:21:12 - 微信打开X5调试,使微信页面可以在谷歌浏览器调试
https://developers.weixin.qq.com/doc/offiaccount/OA_Web_Apps/Web_Developer_Tools.html以上为微信官方文档以下为谷歌浏览器操作微信打开X5调试,使微信页面可以在谷歌浏览器调试展开由于微信对很多页面做了限制,微信开发工作者需要对页面进行调试这个时候可以用到谷歌首先…...
2024/5/8 5:12:25 - C++序列式容器之List的基本使用介绍
写在前面:之前已经整理过vector的相关知识了,本次博客主要整理的是List的基本介绍,以及其构造方法,成员函数,以及内置的一些属性。List 官方介绍:list是可以在常数范围内在任意位置进行插入和删除的序列式容器,并且该容器可以前后双向迭代。 list的底层是双向链表结构,…...
2024/5/8 11:39:16 - org.apache.ibatis.binding.BindingException: Parameter ‘id‘ not found. Available parameters are [bizP
使用mybatis插入数据,然后自动生成主键返回 xml文件代码如下 <!--public int save(@Param("bizPayment")BizPayment bizPayment);--><insert id="save" parameterType="BizPayment" useGeneratedKeys="true" keyProperty=&q…...
2024/4/30 1:20:58 - 【免密登录】一键导入已有公钥到Linux
keys=公钥 mkdir ~/.ssh/ echo ssh-rsa $keys ${USER}@$(hostname)>>~/.ssh/authorized_keys chmod 600 ~/.ssh/authorized_keys && chmod 700 ~/.ssh将自己的公钥复制到上面的shell中即可 是公钥、公钥、公钥,重要的事情说三遍设置免密登录具体方法点这里...
2024/4/30 1:21:15 - grep命令
grep搜索文本 在文件中搜索一个单词$ grep match_pattern filename或者$ grep "match_pattern" filename 返回包含match_pattern的文本行或者从stdin中读取$ echo -e "this is a word \nnext line" | grep word也可以多文件搜索$ grep "match_text&qu…...
2024/4/30 1:21:03 - cf1367E 思维+贪心
1367E 1900的题 题意:给你n个字母,其中仅由a-z26个小写构成,选其中ans个字母围成一个圈使得这个圈顺时针旋转k个位置还是和一开始一样,求你能得到的最大的ans 思路:从大到小枚举最终字符串的长度,对当前长度和k取最大公因数即为字符串单节的长度len,然后求要经过多少次的…...
2024/4/30 1:20:49 - spring boot之安全框架Shiro10
spring boot之安全框架Shiro10shiro简介Apache Shiro 是一个java的安全(权限)框架shiro 可以非常容易的开发出足够好的应用,器不仅可以在javaSE环境,也可以在JavaEE环境.shiro可以完成认证,授权,加密,会话管理,Web集成,缓存等下载地址:http://shiro.apache.org/shiro架构三大核…...
2024/4/30 1:20:42 - 嵌入式LINUX驱动学习之8竞态和并发相关问题(二)自旋锁
嵌入式LINUX驱动学习之8竞态和并发相关问题(二)自旋锁一、头文件、函数及说明二 、代码举例(内核空间)三、代码举例(用户空间)四、测试附A 1.1附A 1.1.1 一、头文件、函数及说明 /* spinlock_t 源码位置 : include/linux/spinlock_types.h */ typedef struct spinlock …...
2024/4/30 1:20:45 - 算法:螺旋矩阵算出N行N列的数组Spiral Matrix II
题目 59. Spiral Matrix II Given a positive integer n, generate a square matrix filled with elements from 1 to n2 in spiral order. Example: Input: 3 Output: [[ 1, 2, 3 ],[ 8, 9, 4 ],[ 7, 6, 5 ] ]解答 思路:数字从0一直递增到n*n, 顺序是顺时针先转完外层,接着…...
2024/4/30 1:20:39 - sed操作
sed入门sed可以替换给给定文本中的字符穿,利用正则表达式进行匹配$ sed s/pattern/replace_string/ file OR$ cat file | sed s/pattern/replace_string/file 使用-i选项,可以将替换结果应用与源文件,或者记住重定向保存文件$ sed s/text/replace/ file > newfile$ mv …...
2024/5/8 3:57:02 - 面向对象三大基本特征,五大基本原则
目录面向对象三大基本特性,五大基本原则三大特性:封装三大特性:继承 三大特性:多态 五大基本原则:面向对象三大基本特性,五大基本原则透切理解面向对象三大基本特性是理解面向对象五大基本原则的基础.三大特性:封装所谓封装,也就是把客观事物封装成抽象的类,并且类可以…...
2024/4/30 1:20:49 - Windows10沙盒与VMware不兼容问题
Windows10沙盒与VMware不兼容问题 前几天试了一下win的沙盒模式,感觉有虚拟机的情况下比较鸡肋,就没再管,今天在开启VMware虚拟机时遇到一个问题 报错信息: VMware Workstation和Device / Credential Guard不兼容。禁用Device / Credential Guard后,可以运行VMware Workst…...
2024/4/30 1:20:19 - 新手分享《本人玩幸运飞艇技巧教学》稳赢技巧
新手分享《本人玩幸运飞艇技巧教学》稳赢技巧〖顶尖专业技术团队,导师筘筘;6495796〗精准计划一对一指导稳赚不赔,长久盈利轻松胜率90%以上!也有同感方提供的人...
2024/4/30 1:20:23 - 刷题小记 (21) LeetCode 102 二叉树的层序遍历Ⅰ
LeetCode 102 2020.8.16 我的通过代码 /*** Definition for a binary tree node.* public class TreeNode {* int val;* TreeNode left;* TreeNode right;* TreeNode(int x) { val = x; }* }*/ class Solution {List<Integer> cell = new ArrayList<I…...
2024/4/30 1:20:21
最新文章
- 无人机+垂直起降:微型共轴双旋翼无人机技术详解
微型共轴双旋翼无人机技术是一种独特的无人机设计,它结合了垂直起降(VTOL)能力和微型无人机的灵活性。这种设计允许无人机在无需跑道的情况下垂直起降,并具备在空中悬停和执行各种飞行动作的能力。 适用于集群控制,荷载…...
2024/5/8 13:09:32 - 梯度消失和梯度爆炸的一些处理方法
在这里是记录一下梯度消失或梯度爆炸的一些处理技巧。全当学习总结了如有错误还请留言,在此感激不尽。 权重和梯度的更新公式如下: w w − η ⋅ ∇ w w w - \eta \cdot \nabla w ww−η⋅∇w 个人通俗的理解梯度消失就是网络模型在反向求导的时候出…...
2024/5/7 10:36:02 - 01背包问题 小明的背包
2.小明的背包1 - 蓝桥云课 (lanqiao.cn) #include <bits/stdc.h> using namespace std; const int N1010;//开始写的105 开小了 样例过了但最后只过了很少一部分 int n,m; int v[N],w[N]; int f[N][N];int main() {cin>>n>>m;for(int i1;i<n;i){cin>&…...
2024/5/5 8:41:06 - 游戏引擎架构01__引擎架构图
根据游戏引擎架构预设的引擎架构来构建运行时引擎架构 ...
2024/5/6 18:32:42 - 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/7 19:05:20 - 【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/7 22:31:36 - Spring cloud负载均衡@LoadBalanced LoadBalancerClient
LoadBalance vs Ribbon 由于Spring cloud2020之后移除了Ribbon,直接使用Spring Cloud LoadBalancer作为客户端负载均衡组件,我们讨论Spring负载均衡以Spring Cloud2020之后版本为主,学习Spring Cloud LoadBalance,暂不讨论Ribbon…...
2024/5/8 1:37:40 - TSINGSEE青犀AI智能分析+视频监控工业园区周界安全防范方案
一、背景需求分析 在工业产业园、化工园或生产制造园区中,周界防范意义重大,对园区的安全起到重要的作用。常规的安防方式是采用人员巡查,人力投入成本大而且效率低。周界一旦被破坏或入侵,会影响园区人员和资产安全,…...
2024/5/7 14:19:30 - VB.net WebBrowser网页元素抓取分析方法
在用WebBrowser编程实现网页操作自动化时,常要分析网页Html,例如网页在加载数据时,常会显示“系统处理中,请稍候..”,我们需要在数据加载完成后才能继续下一步操作,如何抓取这个信息的网页html元素变化&…...
2024/5/8 1:37:39 - 【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/7 16:57:02 - 【洛谷算法题】P5713-洛谷团队系统【入门2分支结构】
👨💻博客主页:花无缺 欢迎 点赞👍 收藏⭐ 留言📝 加关注✅! 本文由 花无缺 原创 收录于专栏 【洛谷算法题】 文章目录 【洛谷算法题】P5713-洛谷团队系统【入门2分支结构】🌏题目描述🌏输入格…...
2024/5/7 14:58:59 - 【ES6.0】- 扩展运算符(...)
【ES6.0】- 扩展运算符... 文章目录 【ES6.0】- 扩展运算符...一、概述二、拷贝数组对象三、合并操作四、参数传递五、数组去重六、字符串转字符数组七、NodeList转数组八、解构变量九、打印日志十、总结 一、概述 **扩展运算符(...)**允许一个表达式在期望多个参数࿰…...
2024/5/7 1:54:46 - 摩根看好的前智能硬件头部品牌双11交易数据极度异常!——是模式创新还是饮鸩止渴?
文 | 螳螂观察 作者 | 李燃 双11狂欢已落下帷幕,各大品牌纷纷晒出优异的成绩单,摩根士丹利投资的智能硬件头部品牌凯迪仕也不例外。然而有爆料称,在自媒体平台发布霸榜各大榜单喜讯的凯迪仕智能锁,多个平台数据都表现出极度异常…...
2024/5/7 21:15:55 - Go语言常用命令详解(二)
文章目录 前言常用命令go bug示例参数说明 go doc示例参数说明 go env示例 go fix示例 go fmt示例 go generate示例 总结写在最后 前言 接着上一篇继续介绍Go语言的常用命令 常用命令 以下是一些常用的Go命令,这些命令可以帮助您在Go开发中进行编译、测试、运行和…...
2024/5/8 1:37:35 - 用欧拉路径判断图同构推出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/7 16:05:05 - 【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/7 16:04:58 - 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/8 1:37:32 - 【论文阅读】MAG:一种用于航天器遥测数据中有效异常检测的新方法
文章目录 摘要1 引言2 问题描述3 拟议框架4 所提出方法的细节A.数据预处理B.变量相关分析C.MAG模型D.异常分数 5 实验A.数据集和性能指标B.实验设置与平台C.结果和比较 6 结论 摘要 异常检测是保证航天器稳定性的关键。在航天器运行过程中,传感器和控制器产生大量周…...
2024/5/7 16:05:05 - --max-old-space-size=8192报错
vue项目运行时,如果经常运行慢,崩溃停止服务,报如下错误 FATAL ERROR: CALL_AND_RETRY_LAST Allocation failed - JavaScript heap out of memory 因为在 Node 中,通过JavaScript使用内存时只能使用部分内存(64位系统&…...
2024/5/8 1:37:31 - 基于深度学习的恶意软件检测
恶意软件是指恶意软件犯罪者用来感染个人计算机或整个组织的网络的软件。 它利用目标系统漏洞,例如可以被劫持的合法软件(例如浏览器或 Web 应用程序插件)中的错误。 恶意软件渗透可能会造成灾难性的后果,包括数据被盗、勒索或网…...
2024/5/8 1:37:31 - JS原型对象prototype
让我简单的为大家介绍一下原型对象prototype吧! 使用原型实现方法共享 1.构造函数通过原型分配的函数是所有对象所 共享的。 2.JavaScript 规定,每一个构造函数都有一个 prototype 属性,指向另一个对象,所以我们也称为原型对象…...
2024/5/8 12:44:41 - C++中只能有一个实例的单例类
C中只能有一个实例的单例类 前面讨论的 President 类很不错,但存在一个缺陷:无法禁止通过实例化多个对象来创建多名总统: President One, Two, Three; 由于复制构造函数是私有的,其中每个对象都是不可复制的,但您的目…...
2024/5/8 9:51:44 - python django 小程序图书借阅源码
开发工具: PyCharm,mysql5.7,微信开发者工具 技术说明: python django html 小程序 功能介绍: 用户端: 登录注册(含授权登录) 首页显示搜索图书,轮播图࿰…...
2024/5/8 1:37:29 - 电子学会C/C++编程等级考试2022年03月(一级)真题解析
C/C++等级考试(1~8级)全部真题・点这里 第1题:双精度浮点数的输入输出 输入一个双精度浮点数,保留8位小数,输出这个浮点数。 时间限制:1000 内存限制:65536输入 只有一行,一个双精度浮点数。输出 一行,保留8位小数的浮点数。样例输入 3.1415926535798932样例输出 3.1…...
2024/5/7 17:09:45 - 配置失败还原请勿关闭计算机,电脑开机屏幕上面显示,配置失败还原更改 请勿关闭计算机 开不了机 这个问题怎么办...
解析如下: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