I want to get a common getUser static method so that I don"t have to manually convert token to user in every controller
public class UserUtil {
@Autowired
private static HttpServletRequest request;
@Autowired
private static HttpServletResponse response;
public static User getUser() {
return null;
}
public static String getUserName() {
System.out.println(request);
System.out.println(response);
String cookieToken =CookieUtils.getCookie(request,"token");
System.out.println("cookieToken:" + cookieToken);
String headerToken = request.getHeader("token");
System.out.println("headerToken:" + headerToken);
return headerToken;
}
}
but this doesn"t get the request object, so what should I do?