直播app开发,个人主页在昵称后面自动显示用户id实现的相关代码
@Target(ElementType.PARAMETER)
@Retention(RetentionPolicy.RUNTIME)
public @interface LoginUserId {
}
@Component
public class LoginUserHandlerMethodArgumentResolver implements HandlerMethodArgumentResolver {
@Autowired
private CommUserUtil commUserUtil;
@Override
public boolean supportsParameter(MethodParameter parameter) {
return parameter.getParameterType().isAssignableFrom(Long.class) && parameter.hasParameterAnnotation(LoginUserId.class);
}
@Override
public Object resolveArgument(MethodParameter parameter, ModelAndViewContainer container,
NativeWebRequest request, WebDataBinderFactory factory) {
// 通过token获取用户
TSacUser sacCurrentUser = commUserUtil.getSacCurrentUser();
if (sacCurrentUser == null) {
return null;
}
return sacCurrentUser.getId();
}
}
@Configuration
public class LoginUserConfigurer implements WebMvcConfigurer {
@Autowired
private LoginUserHandlerMethodArgumentResolver loginUserHandlerMethodArgumentResolver;
@Override
public void addArgumentResolvers(List<HandlerMethodArgumentResolver> argumentResolvers) {
argumentResolvers.add(loginUserHandlerMethodArgumentResolver);
}
}
以上就是 直播app开发,个人主页在昵称后面自动显示用户id实现的相关代码,更多内容欢迎关注之后的文章