定义自定义注解

@Retention(RetentionPolicy.RUNTIME)
@Target(ElementType.PARAMETER)
public @interface Logined {
}

注解处理器

@Component
@Slf4j
public class LoginedArgumentResolver implements HandlerMethodArgumentResolver {
    @Override
    public boolean supportsParameter(MethodParameter parameter) {
        return CurrentRequest.class.isAssignableFrom(parameter.getParameterType());
    }

    @Override
    public Object resolveArgument(MethodParameter parameter, ModelAndViewContainer mavContainer, NativeWebRequest webRequest, WebDataBinderFactory binderFactory) throws Exception {
        HttpServletRequest request = (HttpServletRequest) webRequest.getNativeRequest();
        CurrentRequest currentRequest = (CurrentRequest) request.getAttribute(CurrentRequest.requestAttributeName());
        return currentRequest;
    }
}

使用

    @RequestMapping(value = {"..."})
    public Object create(HttpServletRequest request,
                         @Logined CurrentRequest user) {
                             ......
    }