Spring Boot 日志切面配置,java初级面试必问项目技术

private ThreadLocal requestPath = new ThreadLocal<>();

/**

  • 传入参数

*/

private ThreadLocal inputMap = new ThreadLocal<>();

/**

  • 输出结果

*/

private ThreadLocal outputMap = new ThreadLocal<>();

/**

  • 用户ID

*/

private ThreadLocal userId = new ThreadLocal<>();

/**

  • 开始时间

*/

private ThreadLocal startTimeMills = new ThreadLocal<>();

/**

  • 结束时间

*/

private ThreadLocal endTimeMills = new ThreadLocal<>();

@Before(“execution(* com.rongyixin.sudaidai.cms.controller….(…))”)

public void doBeforeInServiceLayer() {

startTimeMills.set(System.currentTimeMillis());

}

@Around(“execution(* com.rongyixin.sudaidai.cms.controller….(…))”)

public Object getReqAndResInfo(ProceedingJoinPoint proceedingJoinPoint) throws Throwable {

//请求值

RequestAttributes requestAttributes = RequestContextHolder.getRequestAttributes();

ServletRequestAttributes servletRequestAttributes = (ServletRequestAttributes) requestAttributes;

HttpServletRequest request = servletRequestAttributes.getRequest();

requestPath.set(request.getRequestURI());

if (request.getContentType() != null && request.getContentType().toLowerCase().contains(“application/json”)) {

inputMap.set(JSONObject.toJSONString(proceedingJoinPoint.getArgs()));

} else {

inputMap.set(JSONObject.toJSONString(request.getParameterMap()));

}

//响应值

Object res;

res = proceedingJoinPoint.proceed();

if (!(res instanceof ModelAndView)) {

String result = JSONObject.toJSONString(res);

if (StringUtils.isNotBlank(result)) {

if (result.length() > 200) {

result = result.substring(0, 200);

}

outputMap.set(result);

}

}

//用户

try {

CurrentUser currentUser = CurrentUser.get();

userId.set(currentUser.getUserId());

} catch (Exception e) {

userId.set(0L);

小编13年上海交大毕业,曾经在小公司待过,也去过华为、OPPO等大厂,18年进入阿里一直到现在。

深知大多数初中级Java工程师,想要提升技能,往往是自己摸索成长,但自己不成体系的自学效果低效又漫长,而且极易碰到天花板技术停滞不前!

因此收集整理了一份《2024年最新Java开发全套学习资料》送给大家,初衷也很简单,就是希望能够帮助到想自学提升又不知道该从何学起的朋友,同时减轻大家的负担。
img
img
img

由于文件比较大,这里只是将部分目录截图出来,每个节点里面都包含大厂面经、学习笔记、源码讲义、实战项目、讲解视频

如果你觉得这些内容对你有帮助,可以添加下面V无偿领取!(备注Java)
img

录截图出来,每个节点里面都包含大厂面经、学习笔记、源码讲义、实战项目、讲解视频**

如果你觉得这些内容对你有帮助,可以添加下面V无偿领取!(备注Java)
[外链图片转存中…(img-dw9pBpxI-1710890959530)]

  • 10
    点赞
  • 5
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值