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

海口网站排名推广顺义网站优化

海口网站排名推广,顺义网站优化,网络营销推广的研究方向,大丰做网站哪家公司好SpringBootWeb AOP 事务管理 rollbackFor属性 propagation属性 案例 AOP 基础 进阶 通知类型 通知顺序 切入点表达式 execution annotation 连接点 案例 实体类 接口方法 切面类 事务管理 rollbackFor属性 propagation属性 REQUIRED:大部分情况下都是用该传播行为…

SpringBootWeb AOP

事务管理

rollbackFor属性

propagation属性

 案例

AOP

基础

 进阶

通知类型

通知顺序

 切入点表达式

execution

@annotation

连接点

案例

实体类

接口方法

切面类


事务管理

rollbackFor属性

propagation属性

REQUIRED:大部分情况下都是用该传播行为即可。
REOUIRES_NEW:当我们不希望事务之间相互影响时,可以使用该传播行为。比如:下订单前需要记录日志,不论订单保存成功与否,都需要保证日志记录能够记录成功。

 案例

Grep Console插件可用于日志过滤筛选

AOP

基础

 进阶

通知类型

@Slf4j
@Component
@Aspect
public class MyAspect1 {@Pointcut("execution(* com.itheima.service.impl.DeptServiceImpl.*(..))")public void pt() {}@Before("pt()")public void before() {log.info("before ...");}@Around("pt()")public Object around(ProceedingJoinPoint proceedingJoinPoint) throws Throwable {log.info("around before ...");//调用目标对象的原始方法执行Object result = proceedingJoinPoint.proceed();log.info("around after ...");return result;}@After("pt()")public void after() {log.info("after ...");}@AfterReturning("pt()")public void afterReturning() {log.info("afterReturning ...");}@AfterThrowing("pt()")public void afterThrowing() {log.info("afterThrowing ...");}
}

通知顺序

 切入点表达式

execution

//切面类
@Slf4j
@Aspect
@Component
public class MyAspect6 {//@Pointcut("execution(public void com.itheima.service.impl.DeptServiceImpl.delete(java.lang.Integer))")//@Pointcut("execution(void com.itheima.service.impl.DeptServiceImpl.delete(java.lang.Integer))")//@Pointcut("execution(void delete(java.lang.Integer))") //包名.类名不建议省略//@Pointcut("execution(void com.itheima.service.DeptService.delete(java.lang.Integer))")//@Pointcut("execution(void com.itheima.service.DeptService.*(java.lang.Integer))")//@Pointcut("execution(* com.*.service.DeptService.*(*))")//@Pointcut("execution(* com.itheima.service.*Service.delete*(*))")//@Pointcut("execution(* com.itheima.service.DeptService.*(..))")//@Pointcut("execution(* com..DeptService.*(..))")//@Pointcut("execution(* com..*.*(..))")//@Pointcut("execution(* *(..))") //慎用@Pointcut("execution(* com.itheima.service.DeptService.list()) || " +"execution(* com.itheima.service.DeptService.delete(java.lang.Integer))")private void pt(){}@Before("pt()")public void before(){log.info("MyAspect6 ... before ...");}}
@annotation

@annotation 切入点表达式,用于匹配标识有特定注解的方法。

连接点

在Spring中用JoinPoint抽象了连接点,用它可以获得方法执行时的相关信息,如目标类名、方法名、方法参数等。

对于 @Around 通知,获取连接点信息只能使用 ProceedingJoinPoint

对于其他四种通知,获取连接点信息只能使用JoinPoint,它是ProceedingJoinPoint 的父类型

//切面类
@Slf4j
@Aspect
@Component
public class MyAspect8 {@Pointcut("execution(* com.itheima.service.DeptService.*(..))")private void pt(){}@Before("pt()")public void before(JoinPoint joinPoint){log.info("MyAspect8 ... before ...");}@Around("pt()")public Object around(ProceedingJoinPoint joinPoint) throws Throwable {log.info("MyAspect8 around before ...");//1. 获取 目标对象的类名 .String className = joinPoint.getTarget().getClass().getName();log.info("目标对象的类名:{}", className);//2. 获取 目标方法的方法名 .String methodName = joinPoint.getSignature().getName();log.info("目标方法的方法名: {}",methodName);//3. 获取 目标方法运行时传入的参数 .Object[] args = joinPoint.getArgs();log.info("目标方法运行时传入的参数: {}", Arrays.toString(args));//4. 放行 目标方法执行 .Object result = joinPoint.proceed();//5. 获取 目标方法运行的返回值 .log.info("目标方法运行的返回值: {}",result);log.info("MyAspect8 around after ...");return result;}
}

案例

步骤
准备:
在案例工程中引入AOP的起步依赖
导入资料中准备好的数据库表结构,并引入对应的实体类
编码:
自定义注解 @Log
定义切面类,完成记录操作日志的逻辑
获取当前登录用户
获取request对象,从请求头中获取到jwt令牌,解析令牌获取出当前用户的id。

实体类

接口方法

切面类

@Slf4j
@Aspect
@Component
public class LogAspect {@Autowiredprivate OperateLogMapper operateLogMapper;@Autowiredprivate HttpServletRequest request;@Around("@annotation(com.itheima.anno.Log)")public Object recordLog(ProceedingJoinPoint joinPoint) throws Throwable {String jwt = request.getHeader("token");Claims claims = JwtUtils.parseJWT(jwt);Integer operateUser = (Integer)claims.get("id");LocalDateTime operateTime= LocalDateTime.now();String className = joinPoint.getTarget().getClass().getName();String methodName = joinPoint.getSignature().getName();Object[] args = joinPoint.getArgs();String methodParams = Arrays.toString(args);long begin = System.currentTimeMillis();Object result=joinPoint.proceed();long end = System.currentTimeMillis();String returnValue = JSONObject.toJSONString(result);Long costTime = end - begin;OperateLog oprateLog= new OperateLog(null,operateUser,operateTime,className,methodName,methodParams,returnValue,costTime);operateLogMapper.insert(oprateLog);log.info("aop记录日志成功{}",oprateLog);return result;}
}

http://www.yayakq.cn/news/877191/

相关文章:

  • wordpress地址和站点地址蔚县网站建设公司
  • 建筑搜索网站wordpress分类数据库参数
  • 网站建设 博贤科技哪里做网站
  • 一般小型教育网站的建设和开发做网站程序的步骤
  • 网站开发信息平台项目总结关于网页制作的毕业设计
  • 建站之星服务器WordPress移动端加搜索框
  • 网站设计是什么提升网站知名度
  • 义乌建设公司网站烟台网站制作专业
  • 东莞网站推广排名水果 网站源码
  • 做网站语言最好头像制作器
  • 网站服务器转移视频吗广州定制网站建设
  • 网站服务器宽带dedecms菜谱网站源码
  • 昆山专业做网站用wix做网站需要备案吗
  • 网站开发大概需要多少钱wordpress怎么改中文
  • 建站用wordpress好吗快速建站软件排名
  • 网站后台安装三里屯网站建设
  • 2345浏览器网站进入唐山哪个公司做网站
  • 大理石在哪些网站做宣传前期的网站建设的难度
  • 电子商务网站建设问题重庆竣工验收备案网上查询
  • 网站百度收录查询杭州高端网站建设到蓝韵网络
  • 锤子 网站 模版开平小学学生做平网站
  • 做暧小说在线观看网站室内装饰设计人员
  • 网站建设与优化推广的话术wordpress大学添加背景音乐
  • 网站建设整体流程wordpress 域名
  • 企业网站 微信里怎么做网站开发方案怎么写
  • 桓台网站建设python是做什么的
  • 网站拓展关键词怎么做杭州关键词自动排名
  • 乐云seo网站建设公司公司建设网站的分录
  • 漆包线 东莞网站建设网页加速器免费
  • 如何建立公司网站南通丝网外贸做哪些网站