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

通辽网站开发招聘西部数码网站管理助手v4.0

通辽网站开发招聘,西部数码网站管理助手v4.0,网站数据库做好了 怎么做网页,山西手机版建站系统哪家好文章目录一、常用的场景1. 请求拦截2. 异步保存轨迹二、案例实战2.1. pom2.2. 自定义注解2.3. aop拦截2.4. 测试类2.5. 保存日志一、常用的场景 1. 请求拦截 通过aop 请求拦截#xff0c;举个例子#xff0c;第三方厂商请求平台接口#xff0c;先去数据库查询该接口#… 文章目录一、常用的场景1. 请求拦截2. 异步保存轨迹二、案例实战2.1. pom2.2. 自定义注解2.3. aop拦截2.4. 测试类2.5. 保存日志一、常用的场景 1. 请求拦截 通过aop 请求拦截举个例子第三方厂商请求平台接口先去数据库查询该接口此ip是否有访问权限有如果就通过继续下面的逻辑否则权限访问拦截请求到此结束 2. 异步保存轨迹 见下面案例说一下思路 也是同理同样通过拦截器来实现的利用下的注解即可案例中柚子 Aspect Pointcut(“execution( * com.gblfy.logboot...*(…))”)//两个…代表所有子目录最后括号里的两个…代表所有参数 After Around 二、案例实战 2.1. pom dependencygroupIdorg.springframework.boot/groupIdartifactIdspring-boot-starter-aop/artifactId/dependencydependencygroupIdorg.aspectj/groupIdartifactIdaspectjweaver/artifactId/dependency2.2. 自定义注解 package com.gblfy.logboot.annotation;import java.lang.annotation.ElementType; import java.lang.annotation.Retention; import java.lang.annotation.RetentionPolicy; import java.lang.annotation.Target;Retention(RetentionPolicy.RUNTIME) //注解作用的位置ElementType.METHOD表示该注解仅能作用于方法上 Target(ElementType.METHOD) public interface Log {String value() default ; }2.3. aop拦截 package com.gblfy.logboot;import org.aspectj.lang.JoinPoint; import org.aspectj.lang.ProceedingJoinPoint; import org.aspectj.lang.annotation.*; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; 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.Arrays;/*** 日志文件记录*/ Aspect Component public class WebLogAspect {private static final Logger logger LoggerFactory.getLogger(WebLogAspect.class);AutowiredHttpServletRequest request;Pointcut(execution( * com.gblfy.logboot.*.*.*(..)))//两个..代表所有子目录最后括号里的两个..代表所有参数public void logPointCut() {}Before(logPointCut())public void doBefore(JoinPoint joinPoint) throws Throwable {// 接收到请求记录请求内容ServletRequestAttributes attributes (ServletRequestAttributes) RequestContextHolder.getRequestAttributes();HttpServletRequest request attributes.getRequest();// 记录下请求内容logger.info(请求地址 : request.getRequestURL().toString());logger.info(HTTP METHOD : request.getMethod());// 获取真实的ip地址//logger.info(IP : WebUtils.getIpAddress(request));logger.info(CLASS_METHOD : joinPoint.getSignature().getDeclaringTypeName() . joinPoint.getSignature().getName());logger.info(参数 : Arrays.toString(joinPoint.getArgs())); // loggger.info(参数 : joinPoint.getArgs());}After(logPointCut())public void doAfter(JoinPoint joinPoint) throws Throwable {System.out.println(request--- request.getAttribute(aa));}Around(logPointCut())public Object doAround(ProceedingJoinPoint pjp) throws Throwable {long startTime System.currentTimeMillis();Object ob pjp.proceed();// ob 为方法的返回值logger.info(耗时 : (System.currentTimeMillis() - startTime));return ob;} } 2.4. 测试类 package com.gblfy.logboot.controller;import com.gblfy.logboot.annotation.Log; import org.springframework.web.bind.annotation.PathVariable; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestParam; import org.springframework.web.bind.annotation.RestController;import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse;RequestMapping(/log) RestController(日志控制器) public class LogController {Log(测试收集日志)RequestMapping(/save)public String saveLog(RequestParam(name token) String token,RequestParam(name name) String name,HttpServletRequest request, HttpServletResponse response) {System.out.println(开始收集logtokenname);request.setAttribute(aa,assddddd);return 收集日志succes333s;} // http://localhost:8080/log/save?token123 }2.5. 保存日志
http://www.yutouwan.com/news/86531/

相关文章:

  • 诸城手机网站建设农产品网站建设投标书
  • 网站建设项目方案ppt做网站编辑需要看什么书
  • 什么是网站开发类课程安徽徐州网站建设公司
  • 耒阳市古雍网站建设店广告法
  • 做调查问卷能挣钱的网站盛唐网站建设
  • 网站制作公司排名前十上海网站建站建设
  • 做推广适合哪些网站吗全球互联网十大网站
  • 怎么查看网站的空间商现在有什么推广平台
  • 单位建设网站的作用意义什么网站能接单做网站
  • 网站没服务器行吗软件商店应用
  • 如何请人创建一个网站深圳网站建设的价格
  • php网站建设制作服务怎么样把以前做的网站删除
  • 爱站网为什么不能用了重庆工商学校官网
  • 网站建设及推广费记什么科目wordpress条文件夹
  • 公司网站发展策划书如何做好一名销售
  • 网站建设的拓扑结构公司网站的关键词推广怎么做
  • 怎么制作一个网站内容软件开发建设网站
  • 济南智能网站建设服务网站加视频
  • 中小企业网站开发wordpress站点目录
  • 电商设计灵感网站番禺厂家关键词优化
  • 网站公司怎么做推广网络营销服务商
  • 个人社团网站怎么做商业计划书免费word版
  • 网站技术方案wordpress模板 开发
  • 杭州哪些做网站公司好网络营销方式多样
  • 淘宝店铺不允许发布网站建设了制作公司网站需要购买域名和服务器吗
  • 西安网站建设gj网架公司有哪些公司
  • 如何查看网站的关键词常州网站建设公司报价
  • 一级a做爰全过程片视频网站wordpress主题配置文件
  • 网站模块图设计发明的网站
  • 大学学风建设专题网站wordpress小工具不显示