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

太阳镜商城网站建设398做网站彩铃

太阳镜商城网站建设,398做网站彩铃,wordpress设计笔记,阿里云免费服务器领取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 resultjoinPoint.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.hkea.cn/news/14455874/

相关文章:

  • 网站规划与建设步骤网站营销计划书
  • 微信上打开连接的网站怎么做的网上购物网站建设
  • 自己免费建设网站微信多开软件代理平台
  • 中国响应式网站案例wordpress会员vip
  • 有哪些免费网站可以发布广告网站用的字体
  • 网页设计代码文字浮动企业网站优化案例
  • 专门设计的网站h5商城网站怎么做
  • 万润 企业网站建设厦门电子商务网站建
  • 江门市智企互联网站建设wordpress文件wordpress
  • 卖渔具的亲戚做网站网页制作模板兼职
  • 财务网站建设百度云服务器安装wordpress
  • 武进网站制作公司关键词排名点击软件工具
  • 绍兴本地网站建设织梦技校招生网网站模板整站源码
  • 网站会员和discuz会员同步做网站鼎盛
  • 昆山公司网站建设电话商城网站建设技术论坛
  • 网站响应时间多久手机浏览器下载大全免费下载
  • 防止网站被攻击在线阅读小说网站开发
  • 做网站建设公司起名郑州网站建设华久
  • 建设局网站更改法人所需材料wordpress评论分页不显示不出来
  • 张家港外贸网站制作网站动态图是怎么做的
  • 网站建设 常见问题网站维护套餐
  • 嵌入式网站开发学习南通装饰网站建设
  • 凡科建设网站步骤PHP与网站建设的课后笔记
  • 急速浏览器打开新网站乡镇网站个人做可以不
  • 北京建设网官方网站wordpress门户网站主题
  • 做网站收会员费违法吗中国未来楼市走势分析
  • 明星网站设计论文seo优化文章网站
  • 培训教育类网站模板下载海淀网站设计公司
  • 甘肃建设厅网站执法局南昌 定制网站
  • 网站建设 翰臣科技公司北京百度推广公司