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

东莞人才市场档案服务中心网站关键词优化多少钱

东莞人才市场档案服务中心,网站关键词优化多少钱,电子商务网站建设规划,家居设计网站推荐需求分析 在SpringBoot系统中,一般会对访问系统的请求做日志记录的需求,确保系统的安全维护以及查看接口的调用情况,可以使用AOP对controller层的接口进行增强,作日志记录。日志保存在数据库当中,为了避免影响接口的响…

需求分析

在SpringBoot系统中,一般会对访问系统的请求做日志记录的需求,确保系统的安全维护以及查看接口的调用情况,可以使用AOP对controller层的接口进行增强,作日志记录。日志保存在数据库当中,为了避免影响接口的响应,降低用户体验度,采用异步的方式记录日志,避免日志记录阻塞接口请求

实现原理

通过定义AOP切面,访问接口之前,使用前置通知记录一些有用的数据,如ip地址、请求方式、操作人等等,接口执行完之后使用后置通知记录本次请求执行的实践、执行结果等等信息。
在这里插入图片描述

实现代码

AOP日志切面

定义切点表达式指向Controller的所有方法,即指向所有接口

/*** @Description 日志切面类*/
@Aspect
@Component
public class SysLogAspect {@AutowiredSysLogDao sysLogDao;/*** 开始时间*/private Long startTime;/*** ip*/private String ip;/*** 请求接口名*/private String interfaceName;/*** 请求方式*/private String methodWays;/*** 请求方法路径*/private String requestMethodUrl;/*** 请求类方法参数*/private String requestArgs;//声明切点@Pointcut("execution(public * com.*.*.controller.*.*(..)) || execution(public * com.*.controller.*.*(..))"private void aspect() {}@Before("aspect()")public void before(JoinPoint joinPoint) throws NoSuchMethodException {//开始访问的时间startTime = System.currentTimeMillis();ServletRequestAttributes requestAttributes = (ServletRequestAttributes) RequestContextHolder.getRequestAttributes();HttpServletRequest request = requestAttributes.getRequest();//获取请求ipip = request.getRemoteAddr();//获取请求方法名interfaceName = request.getRequestURI();//获取请求方式methodWays = request.getMethod();//获取请求方法地址requestMethodUrl = joinPoint.getSignature().toString();//获取请求参数requestArgs = Arrays.toString(joinPoint.getArgs());}@AfterReturning(pointcut = "aspect()")public void methodAfterReturning() {Long endTime = System.currentTimeMillis();//执行时长Double time = (endTime - startTime) / 1000.0;SysLog sysLog = new SysLog();//获取当前用户Subject currentUser = SecurityUtils.getSubject();UserLoginInfo subject = (UserLoginInfo) currentUser.getPrincipal();if (!ObjectUtils.isEmpty(subject)) {//用户名sysLog.setUserName(subject.getUserName());}//用户操作switch (methodWays) {case "GET":sysLog.setOperation(BusinessType.SELECT.getValue());break;case "POST":sysLog.setOperation(BusinessType.INSERT.getValue());break;case "PUT":sysLog.setOperation(BusinessType.UPDATE.getValue());break;case "DELETE":sysLog.setOperation(BusinessType.DELETE.getValue());break;}//请求IPsysLog.setIp(ip);//请求类方法参数sysLog.setParams(requestArgs);//执行时长sysLog.setTime(time.toString());//请求方法路径sysLog.setMethod(requestMethodUrl);//入库时间String createTime = DateTimeUtils.getNowDateTime();sysLog.setCreateTime(createTime);//获取系统接口路径信息列表List<ApiInfo> apiInfos = sysLogDao.selectApiInfos();for (ApiInfo apiInfo : apiInfos) {//调用接口路径与接口信息列表进行匹配if (apiInfo.getApiName().equals(interfaceName)) {//菜单模块sysLog.setMenuModel(apiInfo.getMenuOperation());break;}}//异步新增日志AsyncManager.me().execute(AsyncFactory.recordOper(sysLog));}
}

异步任务管理器(线程池)

定义一个单例的异步任务管理器,使用线程池完成异步操作

/*** @description: 异步任务管理器**/
public class AsyncManager {/*** 操作延迟10毫秒*/private final int OPERATE_DELAY_TIME = 10;/*** 异步操作任务调度线程池*/private ScheduledExecutorService executor = SpringUtils.getBean("scheduledExecutorService");/*** 单例模式*/private AsyncManager(){}private static AsyncManager me = new AsyncManager();public static AsyncManager me(){return me;}/*** 执行任务** @param task 任务*/public void execute(TimerTask task){executor.schedule(task, OPERATE_DELAY_TIME, TimeUnit.MILLISECONDS);}/*** 停止任务线程池*/public void shutdown(){ThreadsUtil.shutdownAndAwaitTermination(executor);}
}

异步工厂

这里定义异步工厂去创建日记记录的任务,同时也方便系统扩展其他的异步操作

public class AsyncFactory {/*** 操作日志记录** @param operLog 操作日志信息* @return 任务task*/public static TimerTask recordOper(final SysLog operLog) {return new TimerTask() {@Overridepublic void run() {// 远程查询操作地点SpringUtils.getBean(SysLogService.class).addSysLogInfo(operLog);}};}}
http://www.dtcms.com/wzjs/221116.html

相关文章:

  • 做电影视频网站赚钱嘛百度seo优
  • 秀米网站怎么做推文百度智能云建站
  • 嘉兴优化网站哪家好未来网络营销的发展趋势
  • 漯河做网站的店东莞seo收费
  • 怎么查一个网站有没有做301针对百度关键词策划和seo的优化
  • h5网站设计steam交易链接是什么
  • wordpress修改页面的titleseo推广优化工具
  • 桐乡建设规划局网站搜索引擎关键词怎么选
  • 网站如何做邮箱订阅号疫情最严重的三个省
  • 孝义网站开发公司广告
  • 做国外贸易的网站站长工具同大全站
  • 推广营销海外网站宁波网络推广seo软件
  • 我需要一个网站cps推广联盟
  • 政府网站建设运维推广网络推广平台
  • 做网站前端用什么技术好淘宝怎么做引流和推广
  • 做一个公司网站一般多少钱怎样优化网站排名靠前
  • html5网站正在建设中模板下载竞价防恶意点击
  • 分享设计的网站培训机构加盟店排行榜
  • 做企业网站不好混seo学习
  • ps学做翻页相册网站百度热门关键词排名
  • 安徽网站建设怎么样广州番禺发布网
  • 重庆是哪个省市宁波 seo排名公司
  • 深圳优秀网站建设价格网上推广怎么弄?
  • 浙江省台州市做网站多少钱电商运营是做什么的
  • 做贸易注册网站用自己名字站长工具使用方法
  • 泰安网站建设公司带云搜索系统
  • 做海外贸易网站中国十大企业培训公司
  • 张家港网站制作网站外链是什么意思
  • 免费制作相册视频网站模板seo关键词查询排名软件
  • 武汉网站搜索优化外贸营销系统