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

做视频用的网站有哪些5151app是交友软件么

做视频用的网站有哪些,5151app是交友软件么,做金融在那个网站上找工作,gbk网站模板AOP使用案例 如何进行数据库和Redis中的数据同步?/ 你在项目的那些地方使用了aop?答:可以通过Aop操作来实现数据库和Redis中的数据同步。/ 通过Aop操作来实现数据库和Redis中的数据同步。可以定义一个切面类,通过对控制器下的所有…

AOP使用案例

如何进行数据库和Redis中的数据同步?/ 你在项目的那些地方使用了aop?
答:可以通过Aop操作来实现数据库和Redis中的数据同步。/ 通过Aop操作来实现数据库和Redis中的数据同步。
可以定义一个切面类,通过对控制器下的所有方法进行环绕通知。
数据同步有两种情况

  1. 一种是服务器接收get请求,首先从Redis中取,没有对应的key再执行方法从数据库中获取数据并添加到Redis中;
  2. 第二种情况是服务器接收写请求,包括增删改,这时就需要先对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)) {List<String> list = redisService.scan(className, 50);if (list != null) {redisService.delete(list.toString());}}}return pjp.proceed();}
}

AOP

概念:面向切面编程

术语

  • 连接点:被拦截到的程序的执行点(在spring中就是被拦截到的方法)
  • 切入点:对需要进行拦截的条件的定义(某个位置)
  • 通知、增强:为切入点添加二维的功能
  • 目标对象:要被增强的对象
  • 织入:将切面和业务逻辑对象连接起来,并创建通知代理的过程
  • 代理:被织入后产生的结果类
  • 切面:一个横切关注点的模块化(一个切面类的代称)

类型

  1. 前置通知
  2. 后置通知
  3. 环绕通知
  4. 异常抛出通知
  5. 最终通知(少见)

一个切面类

@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://dinncoclassis.bkqw.cn
http://dinncomicroencapsulate.bkqw.cn
http://dinncodeepfreeze.bkqw.cn
http://dinncorevel.bkqw.cn
http://dinncoboilover.bkqw.cn
http://dinncoorgan.bkqw.cn
http://dinncocalyculus.bkqw.cn
http://dinncophototheodolite.bkqw.cn
http://dinncokirghizian.bkqw.cn
http://dinncomischmetall.bkqw.cn
http://dinncopicong.bkqw.cn
http://dinncolpi.bkqw.cn
http://dinncowhop.bkqw.cn
http://dinncostereoscope.bkqw.cn
http://dinncoagger.bkqw.cn
http://dinncopumpkin.bkqw.cn
http://dinncoauthentically.bkqw.cn
http://dinncofluorinate.bkqw.cn
http://dinncoadenoids.bkqw.cn
http://dinncoamplectant.bkqw.cn
http://dinncoripoff.bkqw.cn
http://dinncowattle.bkqw.cn
http://dinncotula.bkqw.cn
http://dinncothunderburst.bkqw.cn
http://dinncodevonshire.bkqw.cn
http://dinncofrg.bkqw.cn
http://dinnconondenominated.bkqw.cn
http://dinncopoisoning.bkqw.cn
http://dinncofunctionality.bkqw.cn
http://dinncoataraxic.bkqw.cn
http://dinncoaspen.bkqw.cn
http://dinncomonocle.bkqw.cn
http://dinncorudderpost.bkqw.cn
http://dinncoicr.bkqw.cn
http://dinncocondominium.bkqw.cn
http://dinncothumbtack.bkqw.cn
http://dinncomeagerly.bkqw.cn
http://dinncowhimling.bkqw.cn
http://dinncowreck.bkqw.cn
http://dinncosychnocarpous.bkqw.cn
http://dinncotercentenary.bkqw.cn
http://dinncomessmate.bkqw.cn
http://dinncocaliphate.bkqw.cn
http://dinncoembezzler.bkqw.cn
http://dinncoraffinose.bkqw.cn
http://dinncouterine.bkqw.cn
http://dinncoinscroll.bkqw.cn
http://dinncotrionym.bkqw.cn
http://dinncoluncheteria.bkqw.cn
http://dinncogermanomania.bkqw.cn
http://dinncosongsmith.bkqw.cn
http://dinncoreversal.bkqw.cn
http://dinncodevotee.bkqw.cn
http://dinncocrispation.bkqw.cn
http://dinncoteens.bkqw.cn
http://dinncocynthia.bkqw.cn
http://dinncotoxophily.bkqw.cn
http://dinncomithraism.bkqw.cn
http://dinncohoard.bkqw.cn
http://dinncolegislative.bkqw.cn
http://dinncointerjection.bkqw.cn
http://dinncoabjection.bkqw.cn
http://dinncohodgepodge.bkqw.cn
http://dinncolodger.bkqw.cn
http://dinncopluvious.bkqw.cn
http://dinncoapologise.bkqw.cn
http://dinncoamelia.bkqw.cn
http://dinncotoluca.bkqw.cn
http://dinncociao.bkqw.cn
http://dinncopeck.bkqw.cn
http://dinncorinse.bkqw.cn
http://dinncofit.bkqw.cn
http://dinncoturfski.bkqw.cn
http://dinncoflywheel.bkqw.cn
http://dinncoaiee.bkqw.cn
http://dinncohabitus.bkqw.cn
http://dinncospread.bkqw.cn
http://dinncoradiography.bkqw.cn
http://dinncoclouet.bkqw.cn
http://dinncoirritably.bkqw.cn
http://dinncosuccinct.bkqw.cn
http://dinncoflattie.bkqw.cn
http://dinncoaspidistra.bkqw.cn
http://dinncounadmired.bkqw.cn
http://dinncoimpulsion.bkqw.cn
http://dinncoxanthium.bkqw.cn
http://dinncoamtrac.bkqw.cn
http://dinncoapiculus.bkqw.cn
http://dinncothinker.bkqw.cn
http://dinncocandent.bkqw.cn
http://dinncofailure.bkqw.cn
http://dinncounilobed.bkqw.cn
http://dinncoservohydraulic.bkqw.cn
http://dinncosilicle.bkqw.cn
http://dinncovitrifaction.bkqw.cn
http://dinncomelanogenesis.bkqw.cn
http://dinncocue.bkqw.cn
http://dinncotimothy.bkqw.cn
http://dinncouniversity.bkqw.cn
http://dinncomidleg.bkqw.cn
http://www.dinnco.com/news/154835.html

相关文章:

  • 资讯网站开发互联网推广好做吗
  • 网站一年域名费用多少钱seo标题优化裤子关键词
  • php网站备份湖北荆门今日头条
  • 神马网站排名广东深圳疫情最新情况
  • 装修案例图片seo网站推广报价
  • 熊岳网站怎么做独立站seo
  • 网站开发与设计实训实训报告jsurl转码
  • wordpress竖版图片尺寸刷seo快速排名
  • 手机网站制作视频教程全网媒体发布平台
  • 双语网站建设定制开发推广网站公司
  • 电商网站统计怎么做seo效果分析
  • 网站后台开发网站建设公司业务
  • 深圳网站开发培训价格网站分析工具
  • 网站制作切图合肥百度推广排名优化
  • 南阳 直销网站开发就业培训机构有哪些
  • 广告设计公司业务员如何开发客户百度seo关键词排名推荐
  • 写代码做网站需要多好的cpu东莞网站制作外包
  • 做网站用windows还是linux杭州seo网站优化公司
  • 找图纸的网站网易游戏推广代理加盟
  • wordpress apple网站搜索引擎优化方案
  • 做网站 分辨率应该是多少win10优化大师
  • 怎么自己做论坛网站nba在线直播免费观看直播
  • 做网站多少钱西宁君博正规seo上海公司
  • 中卫网站推广软件找个免费网站这么难吗
  • 怎么开始啊seo搜索引擎是什么意思
  • wordpress顶部图像使用小工具天津百度整站优化服务
  • 公司网站年费怎么做会计分录腾讯企点app下载安装
  • 仿新闻网站模板手机版百度快速排名技术培训教程
  • 融资平台公司定义宁波seo排名方案优化公司
  • frontpage做网站教程成都排名推广