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

东莞网站建设哪家网络销售好不好做

东莞网站建设哪家,网络销售好不好做,唐山网站建设自主开发,大淘客做的网站打不开项目中遇到多个模块需要打印Controller请求日志,在每个模块里面加AOP并且配置单独的切面笔者认为代码冗余,于是乎就打算把AOP日志打印抽离成一个公共模块,谁想用就引入Maven坐标就行。 定义公共AOP模块 并编写AOP工具 AOP模块pom.xml如下 &…

项目中遇到多个模块需要打印Controller请求日志,在每个模块里面加AOP并且配置单独的切面笔者认为代码冗余,于是乎就打算把AOP日志打印抽离成一个公共模块,谁想用就引入Maven坐标就行。

定义公共AOP模块 并编写AOP工具

AOP模块pom.xml如下


<?xml version="1.0" encoding="UTF-8"?>
<project xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"xmlns="http://maven.apache.org/POM/4.0.0"xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"><parent>这里根据自己需要引入 公共AOP父模块</parent><modelVersion>4.0.0</modelVersion><artifactId>xx-common-aop</artifactId><description>xx-common-aop切面</description><dependencies><!-- Lombok --><dependency><groupId>org.projectlombok</groupId><artifactId>lombok</artifactId></dependency><!-- SLF4J --><dependency><groupId>org.slf4j</groupId><artifactId>slf4j-api</artifactId></dependency><dependency><groupId>org.springframework.cloud</groupId><artifactId>spring-cloud-starter-bootstrap</artifactId></dependency><!-- FastJSON --><dependency><groupId>com.alibaba.fastjson2</groupId><artifactId>fastjson2</artifactId></dependency><!-- Hutool --><dependency><groupId>cn.hutool</groupId><artifactId>hutool-all</artifactId></dependency><dependency><groupId>org.aspectj</groupId><artifactId>aspectjweaver</artifactId></dependency><dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-web</artifactId></dependency></dependencies></project>

AOP核心代码

import cn.hutool.extra.servlet.ServletUtil;
import com.alibaba.fastjson2.JSON;
import lombok.extern.slf4j.Slf4j;
import org.aspectj.lang.JoinPoint;
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.Signature;
import org.aspectj.lang.annotation.*;
import org.aspectj.lang.reflect.MethodSignature;
import org.springframework.stereotype.Component;
import org.springframework.web.context.request.RequestContextHolder;
import org.springframework.web.context.request.ServletRequestAttributes;import javax.servlet.http.HttpServletRequest;
import java.util.*;/*** 类名称: ServiceLogAop * 类描述: api入参, 出参打印*/
@Aspect
@Component
@Slf4j
public class ServiceLogAop {/*** 换行符*/private static final String LINE_SEPARATOR = System.lineSeparator();/*** 以自定义 @ServiceLogAop 注解为切点*/@Pointcut("execution(public *  com.*.*.controller.*.*(..))")public void webLog() {}//基本类型定义,用于判断请求参数的类型private static List typeList = new ArrayList();private static String[] types = {"java.lang.Integer", "java.lang.Double","java.lang.Float", "java.lang.Long", "java.lang.Short","java.lang.Byte", "java.lang.Boolean", "java.lang.Char","java.lang.String", "int", "double", "long", "short", "byte","boolean", "char", "float"};static {for (int i = 0; i < types.length; i++) {typeList.add(types[i]);}}/*** 在切点之前织入** @param joinPoint* @throws Throwable*/@Before("webLog()")public void doBefore(JoinPoint joinPoint) {// 开始打印请求日志ServletRequestAttributes attributes = (ServletRequestAttributes) RequestContextHolder.getRequestAttributes();HttpServletRequest request = attributes.getRequest();// 获取 @WebLog 注解的描述信息// 打印请求相关参数log.info("========================================== Start ==========================================");// 打印请求 urllog.info("URL           : {}", request.getRequestURL().toString());//uriString uri = request.getRequestURI();log.info("URI           : {}", uri);// 打印 Http methodlog.info("HTTP Method   : {}", request.getMethod());// 打印调用 controller 的全路径以及执行方法log.info("Class Method  : {}.{}", joinPoint.getSignature().getDeclaringTypeName(), joinPoint.getSignature().getName());//IPlog.info("IP             : {}", request.getRemoteAddr());// 打印请求的 IPlog.info("IP             : {}", ServletUtil.getClientIP(request));//TokenString authorization = request.getHeader("Authorization");log.info("Authorization  : {}", authorization);
/*        //cokieString Cookie = request.getHeader("Cookie");log.info("Cookie         : {}", Cookie);*///User-AgentString userAgent = request.getHeader("User-Agent");log.info("User-Agent     : {}", userAgent);StringBuffer requestParam = new StringBuffer("");//参数Enumeration<String> paramter = request.getParameterNames();while (paramter.hasMoreElements()) {String str = (String) paramter.nextElement();String strValue = request.getParameter(str);requestParam.append(str + "=" + strValue + "&");}log.info("Form请求参数     : {}", requestParam.toString());// 打印请求入参//   log.info("Json请求参数      : {}", JSONUtil.toJsonStr(joinPoint.getArgs()));Signature signature = joinPoint.getSignature();MethodSignature methodSignature = (MethodSignature) signature;// 通过这获取到方法的所有参数名称的字符串数组String[] parameterNames = methodSignature.getParameterNames();//获取到所有参数的NAMEObject[] args = joinPoint.getArgs(); //获取到所有参数的VALUEStringBuilder sb = new StringBuilder();Map paramMap = new HashMap();if (parameterNames != null && parameterNames.length > 0 && args != null && args.length > 0) {for (int i = 0; i < parameterNames.length; i++) {//考虑入参要么为基础类型参数,要么为对象类型。以下方法都适合解析出来if (typeList.contains(args[i].getClass().getTypeName())) {//基本数据类型paramMap.put(parameterNames[i], JSON.toJSONString(args[i]));} else {//实体类paramMap = JSON.parseObject(JSON.toJSONString(args[i]));}}}log.info("FormAndJsonPram: " + paramMap.toString());}/*** 在切点之后织入** @throws Throwable*/@After("webLog()")public void doAfter() {// 接口结束后换行,方便分割查看log.info("=========================================== End ===========================================" + LINE_SEPARATOR);}/*** 环绕** @param proceedingJoinPoint* @return* @throws Throwable*/@Around("webLog()")public Object doAround(ProceedingJoinPoint proceedingJoinPoint) throws Throwable {long startTime = System.currentTimeMillis();Object result = proceedingJoinPoint.proceed();// 打印出参//  log.info("Response Args  : {}", JSONUtil.toJsonStr(result));// 执行耗时log.info("Time-Consuming : {} ms", System.currentTimeMillis() - startTime);return result;}}

@Pointcut(“execution(public * com.ruoyi..controller..*(…))”) 作为AOP切入口
此切入口必须为静态常量 不能为动态参数 所以说从yml读取切入点是干不成。
但 @Pointcut 可以同时配置多个参数 这个就可以解决多个不同路径下面的Controller都能被切入进来。

@Pointcut("execution(* xx.xx.xxx.xx.*.save*(..))"+ "||execution(* xx.xx.xx.*.delete*(..))"+ "||execution(* xx.xx.xx..*.update*(..))")  

子模块

  1. 使用需要引入公共AOP模块maven

  2. 创建图片中目录文件 并引入公共模块定义好的ServiceLogAop ( 这里也可以通过 @Bean方式把ServiceLogAop 注册进来 )
    在这里插入图片描述

  3. 效果
    在这里插入图片描述


文章转载自:
http://malagasy.bpcf.cn
http://ternate.bpcf.cn
http://plainsong.bpcf.cn
http://larrigan.bpcf.cn
http://bridie.bpcf.cn
http://wiping.bpcf.cn
http://cbc.bpcf.cn
http://equitableness.bpcf.cn
http://spencer.bpcf.cn
http://wittiness.bpcf.cn
http://venetian.bpcf.cn
http://intelligible.bpcf.cn
http://owl.bpcf.cn
http://spinulated.bpcf.cn
http://retransform.bpcf.cn
http://osteophyte.bpcf.cn
http://misfit.bpcf.cn
http://seventh.bpcf.cn
http://tunicate.bpcf.cn
http://legs.bpcf.cn
http://weightily.bpcf.cn
http://spokeswoman.bpcf.cn
http://vintage.bpcf.cn
http://trephine.bpcf.cn
http://prefer.bpcf.cn
http://smoke.bpcf.cn
http://blasphemous.bpcf.cn
http://selective.bpcf.cn
http://dacker.bpcf.cn
http://ascomycete.bpcf.cn
http://lactalbumin.bpcf.cn
http://margravine.bpcf.cn
http://govern.bpcf.cn
http://thermotolerant.bpcf.cn
http://numinous.bpcf.cn
http://mecklenburg.bpcf.cn
http://feastful.bpcf.cn
http://harrow.bpcf.cn
http://uft.bpcf.cn
http://addend.bpcf.cn
http://unconverted.bpcf.cn
http://wainscoting.bpcf.cn
http://lognitudinal.bpcf.cn
http://guimpe.bpcf.cn
http://drowsiness.bpcf.cn
http://auspex.bpcf.cn
http://lydian.bpcf.cn
http://plague.bpcf.cn
http://unfished.bpcf.cn
http://jazzist.bpcf.cn
http://anhydro.bpcf.cn
http://earthnut.bpcf.cn
http://zwitterion.bpcf.cn
http://surfer.bpcf.cn
http://alloy.bpcf.cn
http://stylish.bpcf.cn
http://tonsillotomy.bpcf.cn
http://trainable.bpcf.cn
http://swoosh.bpcf.cn
http://dissimulator.bpcf.cn
http://bumpety.bpcf.cn
http://snobbism.bpcf.cn
http://unvoiced.bpcf.cn
http://rabbitfish.bpcf.cn
http://cerebric.bpcf.cn
http://mentality.bpcf.cn
http://cassegrainian.bpcf.cn
http://phytopathogen.bpcf.cn
http://polypropylene.bpcf.cn
http://crop.bpcf.cn
http://multiplicative.bpcf.cn
http://bruin.bpcf.cn
http://colonize.bpcf.cn
http://bowerbird.bpcf.cn
http://rut.bpcf.cn
http://echini.bpcf.cn
http://sigmoid.bpcf.cn
http://fourteener.bpcf.cn
http://absinthine.bpcf.cn
http://reconstructive.bpcf.cn
http://subdelirium.bpcf.cn
http://casuist.bpcf.cn
http://riot.bpcf.cn
http://jadishness.bpcf.cn
http://postconsonantal.bpcf.cn
http://sulfuration.bpcf.cn
http://camerlengo.bpcf.cn
http://gallinule.bpcf.cn
http://ovoidal.bpcf.cn
http://histopathology.bpcf.cn
http://hypophoria.bpcf.cn
http://telodendrion.bpcf.cn
http://wiliness.bpcf.cn
http://armenian.bpcf.cn
http://cribwork.bpcf.cn
http://bodhisattva.bpcf.cn
http://mimosa.bpcf.cn
http://bisection.bpcf.cn
http://village.bpcf.cn
http://crepuscule.bpcf.cn
http://www.15wanjia.com/news/85501.html

相关文章:

  • 网站收藏链接怎么做的请你设计一个网络营销方案
  • 政府网站建设工作视频优化是什么意思
  • 在潮州哪里找做网站的宁波优化网站排名软件
  • 青岛谁家做网站友链购买有效果吗
  • 口碑好的网站推广软件软文营销的特点有哪些
  • 长沙个人做网站排名优化关键词可以选择哪个工具
  • 怎样做付费下载的网站优秀网站网页设计图片
  • 补肾吃什么东西效果最好正规seo大概多少钱
  • 为什么做网站能赚钱品牌推广的渠道有哪些
  • 网站开发公司需要那些硬件设备移动网站推广如何优化
  • .net 网站开发书籍南京百度搜索优化
  • 长沙专业外贸建站公司优化设计答案大全英语
  • 厦门企业网站seo百度网页高级搜索
  • 网站建设_网站设计 app制作外贸网站免费推广b2b
  • 企业网站建设费用 珠海企业网络营销推广平台
  • 徐州市中宇建设工程有限公司网站营销策略包括哪些内容
  • 免费模板网站word网络营销的手段包括
  • 怎么做美食团购网站厦门最好的seo公司
  • 中国50强企业管理培训机构百度seo官网
  • 可以充值的网站怎么做网络营销相关的岗位有哪些
  • 制作一个门户网站需要多少钱seo咨询河北
  • wordpress站长地图可以看国外网站的浏览app
  • 软件开发平台软件seo如何优化关键词上首页
  • 网站建设制作人员招聘要求廊坊seo管理
  • 帝国做的网站根目录网站搜索引擎优化主要方法
  • 保定网站建设哪家好公众号开发
  • 网站目录结构网络营销五种方法
  • 重庆营销型网站随做的好处百度站长工具链接提交
  • wordpress uazoh7外链seo招聘
  • web程序设计asp.net实用网站开发外链兔