使用AOP来对前端传来的对象参数进行 BaseDto中属性的填充 这样就不用每次都去UserThreadLocal中拿了再又往BaseDto中放了
@Aspect @Component public class UserAspect { @Pointcut("@annotation(org.springframework.web.bind.annotation.RequestMapping) || @annotation(org.springframework.web.bind.annotation.PostMapping) || @annotation(org.springframework.web.bind.annotation.GetMapping)") public void controllerAspect() { } @Before("controllerAspect()") public void doBefore(JoinPoint joinPoint) { if (joinPoint.getArgs() != null && (joinPoint.getArgs()).length != 0) { UserInfoDto userInfo = UserThreadLocal.getNotValid(); if (!Objects.isNull(userInfo) && null != userInfo.getPkUser()) Arrays.stream(joinPoint.getArgs()).forEach(arg -> { if (arg instanceof BaseDto) { ((BaseDto) arg).setUserId(userInfo.getPkUser()); ((BaseDto) arg).setUserName(userInfo.getUserName()); ((BaseDto) arg).setCard(userInfo.getCard()); ((BaseDto) arg).setEamPkDept(userInfo.getPkDept()); ((BaseDto) arg).setEamChineseName(userInfo.getChineseName()); } if (arg instanceof DefaultPageDto) { ((DefaultPageDto) arg).setUserId(userInfo.getPkUser()); ((DefaultPageDto) arg).setUserName(userInfo.getUserName()); ((DefaultPageDto) arg).setCard(userInfo.getCard()); ((DefaultPageDto) arg).setEamPkDept(userInfo.getPkDept()); ((DefaultPageDto) arg).setEamChineseName(userInfo.getChineseName()); } }); } } }