@Aspect @Component public class MethodAspect { @Pointcut("execution(* com.sairobo.heart.modules.app.controller..*.*(..))") public void webLog(){} @Before("webLog()") public void deBefore(JoinPoint joinPoint) throws Throwable { // 接收到请求,记录请求内容 ServletRequestAttributes attributes = (ServletRequestAttributes) RequestContextHolder.getRequestAttributes(); HttpServletRequest request = attributes.getRequest(); HttpServletResponse response = attributes.getResponse(); response.setCharacterEncoding("UTF-8"); response.setContentType("application/json; charset=utf-8"); PrintWriter out = response.getWriter(); String s = null; out.print(s); System.out.println("增强"); }
springboot之AOP(1)前置方法
最新推荐文章于 2024-10-27 20:37:11 发布
本文介绍了一种利用Spring AOP实现Controller层面请求日志记录的方法。通过定义切入点和前置通知,可以在不修改原有业务逻辑的基础上为所有Controller方法添加统一的日志记录功能。
866

被折叠的 条评论
为什么被折叠?



