- pom.xml 导入 springboot aop 依赖
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-aop</artifactId>
</dependency>
- 创建 aspect,在 execution 参数中写上被切的类
@Aspect
@Component
public class IndexAspect {
private static final Logger logger = LoggerFactory.getLogger(IndexAspect.class);
<span class="hljs-comment">// 公用的切点,该类下所有方法</span>
<span class="hljs-meta">@Pointcut</span>(<span class="hljs-string">"execution(public * com.example.IndexController.*(..))"</span>)
<span class="hljs-function"><span class="hljs-keyword">public</span> <span class="hljs-keyword">void</span> <span class="hljs-title">log</span><span class="hljs-params">()</span> </span>{
logger.info(<span class="hljs-string">"调用 log() "</span>);
}
<span class="hljs-comment">// 使用log函数定义的 execution,不执行log()方法</span>
<span class="hljs-meta">@Before</span>(<span class="hljs-string">"log()"</span>)
<span class="hljs-function"><span class="hljs-keyword">public</span> <span class="hljs-keyword">void</span> <span class="hljs-title">doBefore</span><span class="hljs-params">(JoinPoint joinPoint)</span> </span>{
logger.info(<span class="hljs-string">"调用 doBefore"</span>);
ServletRequestAttributes attributes = (ServletRequestAttributes)RequestContextHolder.getRequestAttributes();
logger.info(<span class="hljs-string">"获取 request"</span>);
HttpServletRequest request = attributes.getRequest();
logger.info(<span class="hljs-string">"获取 reponse"</span>);
attributes.getResponse();
logger.info(<span class="hljs-string">"获取 session"</span>);
attributes.getRequest().getSession();
logger.info(<span class="hljs-string">"获取 class:"</span> + joinPoint.getSignature().getDeclaringTypeName().toString());
logger.info(<span class="hljs-string">"获取 args:"</span> + joinPoint.getArgs());
}
<span class="hljs-comment">// 获取返回值</span>
<span class="hljs-meta">@AfterReturning</span>(pointcut = <span class="hljs-string">"log()"</span>, returning = <span class="hljs-string">"object"</span>)
<span class="hljs-function"><span class="hljs-keyword">public</span> <span class="hljs-keyword">void</span> <span class="hljs-title">doAfterReturning</span><span class="hljs-params">(Object object)</span> </span>{
logger.info(<span class="hljs-string">"获取返回值"</span> + object.toString());
}
}
- 启动项目,查看控制台日志
com.example.IndexAspect: 调用 doBefore
com.example.IndexAspect: 获取 request
com.example.IndexAspect: 获取 reponse
com.example.IndexAspect: 获取 session
com.example.IndexAspect: 获取 class:com.example.thymeleaf.IndexController
com.example.IndexAspect: 获取 args:
com.example.IndexAspect: index
</div>
Flutter实战视频-移动电商-34.列表页_小BUG的修复
Flutter实战视频-移动电商-33.列表页_子类和商品列表交互效果
Flutter实战视频-移动电商-32.列表页_小类高亮交互效果制作
Flutter实战视频-移动电商-31.列表页_列表切换交互制作
Flutter实战视频-移动电商-30.列表页_商品列表UI界面布局
Flutter实战视频-移动电商-29.列表页_商品列表数据模型建立
Flutter实战视频-移动电商-28.列表页_商品列表后台接口调试
Flutter实战视频-移动电商-27.列表页_现有Bug修复和完善
Flutter实战视频-移动电商-26.列表页_使用Provide控制子类-2