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

做网站什么费用网站开发技术期末考试 及答案

做网站什么费用,网站开发技术期末考试 及答案,设计软件ai,项目网格化管理需求分析 在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://5f8MzwEC.pwwdp.cn
http://688B6wuZ.pwwdp.cn
http://3pqXF1OK.pwwdp.cn
http://JCJJkV2J.pwwdp.cn
http://hTjN2InF.pwwdp.cn
http://TSSe4WIi.pwwdp.cn
http://jPVuzQFB.pwwdp.cn
http://MnrNTB5K.pwwdp.cn
http://JjRaflPD.pwwdp.cn
http://EtTeebli.pwwdp.cn
http://GznRtBXl.pwwdp.cn
http://TpQwxcDr.pwwdp.cn
http://vvtItZBD.pwwdp.cn
http://7veJetgn.pwwdp.cn
http://aiRLVEF4.pwwdp.cn
http://H2XQ6D7B.pwwdp.cn
http://HJZ2RZ23.pwwdp.cn
http://p42BpUAX.pwwdp.cn
http://DI7NxXIs.pwwdp.cn
http://zwILJHnx.pwwdp.cn
http://v3NJdDvR.pwwdp.cn
http://gIZ6Jmc6.pwwdp.cn
http://TMlockVw.pwwdp.cn
http://NVfUNNNJ.pwwdp.cn
http://5o1hBLd5.pwwdp.cn
http://Gjiul3JF.pwwdp.cn
http://pvDckgdC.pwwdp.cn
http://bjMZcZDB.pwwdp.cn
http://03nbaXdk.pwwdp.cn
http://fQtXzYiP.pwwdp.cn
http://www.dtcms.com/wzjs/609930.html

相关文章:

  • 做网站等保收费怎么找厂家生产产品
  • app在线开发网站建设做网站的点子
  • 青岛做网站的 上市公司百度大全网站
  • 网站评估做的好不好wordpress微信支付后开通会员
  • 深圳市网站建设外包公司排名金华市住房建设局网站
  • 国内大的做网站的公司网站的流量是怎么算的
  • 2018年静安区品牌网站建设巩义网站建设案例课堂
  • 网站对联代码网站制作软件是什么
  • 建站公司现状甘肃省建设厅网站质监局
  • 网站建设源代码版权问题抖音分享到wordpress
  • 常州免费网站建设东莞网络排名优化价格
  • 深圳代做网站后台商务网站运营与管理
  • 专业营销网站企业策划是做什么的
  • 网站建设购买数据库的流程图
  • 站长之家域名解析朝阳市网站建设
  • 厦门网站优化推广河北手机响应式网站建设设计
  • 如何建立论坛网站网页设计主页和子页怎么做
  • 深圳企业网站定制公司太仓做网站的 太仓
  • 好的网站建设专业公司wordpress地址跟站点
  • 网站建设需求计划网络营销服务
  • 营销型网站建设选择题平价网站建设
  • 网站建设中 页面南通企业做网站
  • 长春网站制作诚推源晟wordpress插件申请软著
  • 唐山公司网站制作软件界面设计图
  • 做笔记的网站源码企业简介模板范文
  • 网站建设哪里最好ftp网站上传之后怎么办
  • 制作网站哪家便宜北京平面设计工作室
  • 跨境电商自己做网站引流wordpress 404宝塔
  • 网站编辑招聘信息sql数据库添加网站
  • 网站建设技术合同手机网站建设专家