content: package com.ncst.seckill.config;
  
  import com.ncst.seckill.access.UserContext;
  import org.springframework.core.MethodParameter;
  import org.springframework.stereotype.Service;
  import org.springframework.web.bind.support.WebDataBinderFactory;
  import org.springframework.web.context.request.NativeWebRequest;
  import org.springframework.web.method.support.HandlerMethodArgumentResolver;
  import org.springframework.web.method.support.ModelAndViewContainer;
  
  import com.ncst.seckill.pojo.SkUser;
  
  /**
   * @Date 2020/10/14 12:30
   * @Author by LSY
   * @Description
   */
  @Service
  public class UserArgumentResolver implements HandlerMethodArgumentResolver {
  
      @Override
      public boolean supportsParameter(MethodParameter parameter) {
          Class<?> clazz = parameter.getParameterType();
          return clazz == SkUser.class;
      }
  
      @Override
      public Object resolveArgument(MethodParameter parameter, ModelAndViewContainer mavContainer,
                                    NativeWebRequest webRequest, WebDataBinderFactory binderFactory) throws Exception {
          return UserContext.getUser();
      }
  
  }
  