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

做调查问卷用的网站或软件厦门做网站seo

做调查问卷用的网站或软件,厦门做网站seo,网站开发在线浏览pdf,空间设计公司AOP使用案例 如何进行数据库和Redis中的数据同步#xff1f;/ 你在项目的那些地方使用了aop#xff1f;答#xff1a;可以通过Aop操作来实现数据库和Redis中的数据同步。/ 通过Aop操作来实现数据库和Redis中的数据同步。可以定义一个切面类#xff0c;通过对控制器下的所有… AOP使用案例 如何进行数据库和Redis中的数据同步/ 你在项目的那些地方使用了aop答可以通过Aop操作来实现数据库和Redis中的数据同步。/ 通过Aop操作来实现数据库和Redis中的数据同步。可以定义一个切面类通过对控制器下的所有方法进行环绕通知。数据同步有两种情况 一种是服务器接收get请求首先从Redis中取没有对应的key再执行方法从数据库中获取数据并添加到Redis中第二种情况是服务器接收写请求包括增删改这时就需要先对Redis中的数据进行扫描对特定key对应的的数据进行删除清空再执行方法修改数据库中的内容(没有考虑再次将数据库中的数据同步到Redis是因为如果服务器接收到任一get请求都会自动进行同步) import cn.cnmd.redis.RedisService; import com.alibaba.fastjson2.JSON; import org.aspectj.lang.ProceedingJoinPoint; import org.aspectj.lang.Signature; import org.aspectj.lang.annotation.Around; import org.aspectj.lang.annotation.Aspect; import org.aspectj.lang.annotation.Pointcut; import org.aspectj.lang.reflect.MethodSignature; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Component; import org.springframework.web.bind.annotation.DeleteMapping; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.PostMapping; import org.springframework.web.bind.annotation.PutMapping;import java.lang.reflect.Method; import java.time.Duration; import java.util.List; import java.util.Random; import java.util.concurrent.TimeUnit;Aspect Component public class RedisCacheAspect {private static Random random new Random();Autowiredprivate RedisService redisService;Pointcut(execution(* cn.ctmd.electric.*.controller.*(..)))private void pointcut() {}Around(pointcut())public Object around(ProceedingJoinPoint pjp) throws Throwable {Signature signature pjp.getSignature();MethodSignature methodSignature (MethodSignature) signature;Method method methodSignature.getMethod();String className method.getDeclaringClass().getSimpleName();String methodName method.getName();if (method.isAnnotationPresent(GetMapping.class)) {// get请求Object[] args pjp.getArgs();String cacheKey className :: methodName JSON.toJSONString(args);if (Boolean.TRUE.equals(redisService.hasKey(cacheKey))) {return redisService.get(cacheKey);} else {synchronized (this) {if (Boolean.FALSE.equals(redisService.hasKey(cacheKey))) {Object value pjp.proceed();long expireTime Duration.ofMinutes(5).toMillis() random.nextInt(1000);redisService.set(cacheKey, value, expireTime, TimeUnit.MILLISECONDS);return value;} else {return redisService.get(cacheKey);}}}} else {if (method.isAnnotationPresent(PostMapping.class) || method.isAnnotationPresent(PutMapping.class) || method.isAnnotationPresent(DeleteMapping.class)) {ListString list redisService.scan(className, 50);if (list ! null) {redisService.delete(list.toString());}}}return pjp.proceed();} } AOP 概念面向切面编程 术语 连接点被拦截到的程序的执行点在spring中就是被拦截到的方法切入点对需要进行拦截的条件的定义某个位置通知、增强为切入点添加二维的功能目标对象要被增强的对象织入将切面和业务逻辑对象连接起来并创建通知代理的过程代理被织入后产生的结果类切面一个横切关注点的模块化一个切面类的代称 类型 前置通知后置通知环绕通知异常抛出通知最终通知少见 一个切面类 Aspect public class AspectJAdvice {Before(value execution(* com.qf.spring.aop.service..*(..)))public void before(JoinPoint jp){Object[] args jp.getArgs(); //获取方法参数Signature signature jp.getSignature(); //获取签名if(signature instanceof MethodSignature){ //如果签名是方法签名Method method ((MethodSignature) signature).getMethod(); //获取方法String methodName method.getName();String className method.getDeclaringClass().getName();System.out.println(准备执行方法 className . methodName ,参数 Arrays.toString(args));}}AfterReturning(value execution(* com.qf.spring.aop.service..*(..)), returning returnValue)public void after(JoinPoint jp, Object returnValue){Object[] args jp.getArgs(); //获取方法参数Signature signature jp.getSignature(); //获取签名if(signature instanceof MethodSignature){ //如果签名是方法签名Method method ((MethodSignature) signature).getMethod(); //获取方法String methodName method.getName();String className method.getDeclaringClass().getName();System.out.println(执行完方法 className . methodName ,参数 Arrays.toString(args) ,得到返回值 returnValue);}}AfterThrowing(value execution(* com.qf.spring.aop.service..*(..)), throwing t)public void exception(JoinPoint jp, Throwable t){Object[] args jp.getArgs(); //获取方法参数Signature signature jp.getSignature(); //获取签名if(signature instanceof MethodSignature){ //如果签名是方法签名Method method ((MethodSignature) signature).getMethod(); //获取方法String methodName method.getName();String className method.getDeclaringClass().getName();System.out.println(执行方法时 className . methodName ,参数 Arrays.toString(args) ,发生了异常 t.getMessage());}}Around(execution(* com.qf.spring.aop.service..*(..)))public Object around(ProceedingJoinPoint pjp) throws Throwable {Object[] args pjp.getArgs();//获取方法的参数Object target pjp.getTarget(); //获取代理对象Signature signature pjp.getSignature(); //获取签名if(signature instanceof MethodSignature) { //如果签名是方法签名Method method ((MethodSignature) signature).getMethod(); //获取被拦截的方法对象String methodName method.getName();String className method.getDeclaringClass().getName();try {System.out.println(准备执行方法 className . methodName ,参数 Arrays.toString(args));Object returnValue method.invoke(target, args);System.out.println(执行完方法 className . methodName ,参数 Arrays.toString(args) ,得到返回值 returnValue);return returnValue;} catch (Throwable t){System.out.println(执行方法时 className . methodName ,参数 Arrays.toString(args) ,发生了异常 t.getMessage());throw t;}}return null;} }
http://www.dnsts.com.cn/news/38595.html

相关文章:

  • 网站底部的备案号凡客诚品电话
  • 手机网站表单页面制作公司网站服务器优化
  • 网站前端免费ppt模板下载爱ppt
  • asp.net获取网站虚拟目录怎么创建游戏软件
  • 网站建设案例咨询长沙微信网站
  • 兰州网站制作联系方式搜索引擎优化seo什么意思
  • 上海网站建设哪家比较好网站长期建设 运营计划
  • dz网站后台单位门户网站建设
  • 管理网站建设哪家公司好网站建设手机站
  • 品牌网站建设哪好wordpress怎么破解版
  • 家纺代发网站建设企业网站开发摘要
  • led外贸网站制作网站建设的主题
  • 传统网站和手机网站的区别站长统计黄页网站下载大全
  • 英文网站模板下载菏泽厚德网站建设公司怎么样
  • 邢台12345网站分类信息网站开发
  • 商城网站开发项目分工网站建设投标ppt
  • 苏州建网站的公司招精品课程网站源码
  • 做短视频必备的网站网站优化是往新闻中心发新闻吗
  • 泊头市做网站价格在线刷seo
  • ssc网站建设广东
  • 温州营销网站公司哪家好公司推广哪个平台好
  • 仿顺丰优选网站源码网站做302重定向会怎么样
  • 电脑上wap网站想做一个自己的网站
  • 东莞地图全图淄博网站制作优化推广
  • 关于建设殡葬网站的报告范文重庆网站建设哪家专业
  • 网站排名wordpress 页面 瞄
  • 什么网站可以接活在家做对Wordpress系统的感想
  • 为什么要进行电子商务网站规划能做wordpress的网站
  • 网站建设项目进度计划wordpress mo po
  • 网站怎样做推广前端做图表的网站