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

网站商城前台模板免费下载做智能网站营销话术

网站商城前台模板免费下载,做智能网站营销话术,做网站免费吗,苏州市吴中区住房和城乡建设局网站原理 AOP#xff1a;面向切面编程#xff08;spring AOP#xff09; ThreadLocal#xff1a;实现线程范围内的局部变量#xff0c;即ThreadLocal在一个线程中是共享的#xff0c;在不同线程之间是隔离的。ThreadLocal 自定义注解#xff1a;自定义注解 代码实现 自定… 原理 AOP面向切面编程spring AOP ThreadLocal实现线程范围内的局部变量即ThreadLocal在一个线程中是共享的在不同线程之间是隔离的。ThreadLocal 自定义注解自定义注解 代码实现 自定义注解 package com.dd.controller.log;import java.lang.annotation.ElementType; import java.lang.annotation.Retention; import java.lang.annotation.RetentionPolicy; import java.lang.annotation.Target;Target(ElementType.METHOD) Retention(RetentionPolicy.RUNTIME) public interface LogAnnotation {/*** 日志名称*/String description() default ;/*** 日志操作类型*/String type();} 日志切面 package com.dd.controller.log;import lombok.extern.slf4j.Slf4j;import org.aspectj.lang.JoinPoint; import org.aspectj.lang.annotation.*; import org.springframework.core.NamedThreadLocal; import org.springframework.stereotype.Component;import javax.servlet.http.HttpServletRequest; import java.lang.reflect.Method; import java.util.Date; import java.util.HashMap; import java.util.Map;Aspect Component Slf4j public class LogAspect {private static final ThreadLocalDate beginTimeThreadLocal new NamedThreadLocalDate(ThreadLocal beginTime);/*** Controller层切点,注解方式*/Pointcut(annotation(com.dd.controller.log.LogAnnotation))public void controllerAspect() {}/*** 前置通知 (在方法执行之前返回)用于拦截Controller层记录用户的操作的开始时间** param joinPoint 切点* throws InterruptedException*/Before(controllerAspect())public void doBefore(JoinPoint joinPoint) throws InterruptedException {//线程绑定变量该数据只有当前请求的线程可见Date beginTime new Date();beginTimeThreadLocal.set(beginTime);log.info(前置通知 开始时间 beginTime);}/*** 后置通知(在方法执行之后返回) 用于拦截Controller层操作** param joinPoint 切点*/After(controllerAspect())public void after(JoinPoint joinPoint) {try {Object[] objs joinPoint.getArgs();if (objs ! null objs.length 0) {for (Object object : objs) {if (object instanceof HttpServletRequest) {break;}}}String logName getControllerMethodInfo(joinPoint).get(description).toString();String logType getControllerMethodInfo(joinPoint).get(type).toString();//请求开始时间long beginTime beginTimeThreadLocal.get().getTime();long endTime System.currentTimeMillis();log.info(后置通知结束时间{}, logName:{}, logType:{} , endTime, logName, logType);//请求耗时Long logElapsedTime endTime - beginTime;log.info(接口耗时 endTime);} catch (Exception e) {log.error(AOP后置通知异常, e);}}/*** 获取注解中对方法的描述信息 用于Controller层注解** param joinPoint 切点* return 方法描述* throws Exception*/public static MapString, Object getControllerMethodInfo(JoinPoint joinPoint) throws Exception {MapString, Object map new HashMapString, Object(16);//获取目标类名String targetName joinPoint.getTarget().getClass().getName();//获取方法名String methodName joinPoint.getSignature().getName();//获取相关参数Object[] arguments joinPoint.getArgs();//生成类对象Class targetClass Class.forName(targetName);//获取该类中的方法Method[] methods targetClass.getMethods();String description ;String type null;for (Method method : methods) {if (!method.getName().equals(methodName)) {continue;}Class[] clazzs method.getParameterTypes();if (clazzs.length ! arguments.length) {//比较方法中参数个数与从切点中获取的参数个数是否相同原因是方法可以重载哦continue;}description method.getAnnotation(LogAnnotation.class).description();type method.getAnnotation(LogAnnotation.class).type();map.put(description, description);map.put(type, type);}return map;}} package com.dd.controller.log; import lombok.extern.slf4j.Slf4j; import org.aspectj.lang.JoinPoint; import org.aspectj.lang.annotation.*; import org.springframework.core.NamedThreadLocal; import org.springframework.stereotype.Component; import javax.servlet.http.HttpServletRequest; import java.lang.reflect.Method; import java.util.Date; import java.util.HashMap; import java.util.Map; Aspect Component Slf4j public class LogAspect { private static final ThreadLocalDate beginTimeThreadLocal new NamedThreadLocalDate(ThreadLocal beginTime);/*** Controller层切点,注解方式*/ Pointcut(annotation(com.dd.controller.log.LogAnnotation)) public void controllerAspect() {}/*** 前置通知 (在方法执行之前返回)用于拦截Controller层记录用户的操作的开始时间** param joinPoint 切点* throws InterruptedException*/ Before(controllerAspect()) public void doBefore(JoinPoint joinPoint) throws InterruptedException {//线程绑定变量该数据只有当前请求的线程可见Date beginTime new Date();beginTimeThreadLocal.set(beginTime);log.info(前置通知 开始时间 beginTime); }/*** 后置通知(在方法执行之后返回) 用于拦截Controller层操作** param joinPoint 切点*/ After(controllerAspect()) public void after(JoinPoint joinPoint) {try {Object[] objs joinPoint.getArgs();if (objs ! null objs.length 0) {for (Object object : objs) {if (object instanceof HttpServletRequest) {break;}}}String logName getControllerMethodInfo(joinPoint).get(description).toString();String logType getControllerMethodInfo(joinPoint).get(type).toString();//请求开始时间long beginTime beginTimeThreadLocal.get().getTime();long endTime System.currentTimeMillis();log.info(后置通知结束时间{}, logName:{}, logType:{} , endTime, logName, logType);//请求耗时Long logElapsedTime endTime - beginTime;log.info(接口耗时 endTime);} catch (Exception e) {log.error(AOP后置通知异常, e);} }/*** 获取注解中对方法的描述信息 用于Controller层注解** param joinPoint 切点* return 方法描述* throws Exception*/ public static MapString, Object getControllerMethodInfo(JoinPoint joinPoint) throws Exception {MapString, Object map new HashMapString, Object(16);//获取目标类名String targetName joinPoint.getTarget().getClass().getName();//获取方法名String methodName joinPoint.getSignature().getName();//获取相关参数Object[] arguments joinPoint.getArgs();//生成类对象Class targetClass Class.forName(targetName);//获取该类中的方法Method[] methods targetClass.getMethods();String description ;String type null;for (Method method : methods) {if (!method.getName().equals(methodName)) {continue;}Class[] clazzs method.getParameterTypes();if (clazzs.length ! arguments.length) {//比较方法中参数个数与从切点中获取的参数个数是否相同原因是方法可以重载哦continue;}description method.getAnnotation(LogAnnotation.class).description();type method.getAnnotation(LogAnnotation.class).type();map.put(description, description);map.put(type, type);}return map; }} 引用注解 LogAnnotation(description 测试接口, type 测试)GetMapping(/test)public void test() throws Exception {}效果
http://www.dnsts.com.cn/news/163057.html

相关文章:

  • 网站建设应解决的问题dedecms做网站有多快
  • 福州企业网站建设哪家好网站建设维护实训总结
  • 企业网站背景图片手机用什么软件做网站
  • 目前个人网站做地最好是哪几家深圳各区繁华程度排名
  • 做网站怎么买服务器滁州做网站电话号码
  • 门户网站 建设 如何写模板网站开发定制
  • 做树状图的网站78建筑网站
  • 巩义便宜网站建设价格湖北网站建设模板下载
  • 企业网站建设项目计划书建立子目录网站
  • 网站营销策略组合工程建设龙头
  • 网站建设大忌网站定制制作公司
  • ftp网站怎么建立泰安网站建设哪里找
  • 安徽省建设工程造价管理网站网至普的营销型网站布局
  • 网站建设中忽略的字体侵权行为设计的网站有哪些
  • 网站备案有必要吗wordpress文本块字体大小
  • 友链交换网站做的好的学校网站
  • WordPress建站如何解析免费观看电影电视剧的app下载
  • 驻马店 网站制作菠菜建设网站
  • asp网站qq登录南京it外包公司
  • 如何做网站链接使用福州网站建设询q479185700上快
  • 上海网站建设代码怎么做网站把图片发到网上
  • 海外 国内网站建设深圳创业补贴政策2021
  • 网站空间管理面板重庆市建设工程施工安全管理总站
  • 网站建设管理的建议360竞价推广
  • 机关门户网站建设wordpress 私有文章
  • 网站建设的标准化建设是什么牌具做网站
  • 嘉兴做营销型网站设计网站建设人员架构
  • 网站群系统建设思路dw制作wap网站怎么做
  • 河北网站建设方案如何创建一个自己的公众号
  • 湖北省建设厅官方网站八大员建筑八大员培训机构