com.github.houbb.current.user.interceptor.CurrentUserMethodArgumentResolver Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of current-user Show documentation
Show all versions of current-user Show documentation
The current-user tool for java.
package com.github.houbb.current.user.interceptor;
import com.github.houbb.current.user.annotation.CurrentUser;
import com.github.houbb.current.user.constant.CurrentUserConst;
import com.github.houbb.current.user.dto.CurrentUserInfo;
import org.springframework.core.MethodParameter;
import org.springframework.stereotype.Component;
import org.springframework.web.bind.support.WebDataBinderFactory;
import org.springframework.web.context.request.NativeWebRequest;
import org.springframework.web.context.request.RequestAttributes;
import org.springframework.web.method.support.HandlerMethodArgumentResolver;
import org.springframework.web.method.support.ModelAndViewContainer;
/**
* @author binbin.hou
* @since 0.0.12
*/
@Component
public class CurrentUserMethodArgumentResolver implements HandlerMethodArgumentResolver {
@Override
public boolean supportsParameter(MethodParameter parameter) {
return parameter.getParameterType().isAssignableFrom(CurrentUserInfo.class)
&& parameter.hasParameterAnnotation(CurrentUser.class);
}
@Override
public Object resolveArgument(MethodParameter parameter, ModelAndViewContainer mavContainer, NativeWebRequest webRequest, WebDataBinderFactory binderFactory) throws Exception {
return webRequest.getAttribute(CurrentUserConst.CURRENT_USER, RequestAttributes.SCOPE_REQUEST);
}
}