1.记录用户登陆信息,话不多说(原理自行百度,可参考),直接上代码
public class SessionManager {
private static ThreadLocal<UserSession> userSession = new ThreadLocal();
public SessionManager() {
}
public static void setUserSession(UserSession userSession) {
SessionManager.userSession.set(userSession);
}
public static UserSession getUserSession() {
return (UserSession)userSession.get();
}
public static ThreadLocal<UserSession> getThreadLocalObject() {
return userSession;
}
}
import org.springframework.stereotype.Component;
@Component
public class UserSession {
private Long userId;
private String userAccount;
private String userName;
private long currentTimeMillis;
private String role;
private String roleId;
private String clientId;
public UserSession() {
}
public Long getUserId() {
return this.userId;
}
public void setUserId(Long userId) {
this.userId = userId;
}
public String getUserAccount() {
return this.userAccount;
}
public void setUserAccount(String userAccount) {
this.userAccount = userAccount;
}
public String getUserName() {
return this.userName;
}
public void setUserName(String userName) {
this.userName = userName;
}
public long getCurrentTimeMillis() {
return this.currentTimeMillis;
}
public void setCurrentTimeMillis(long currentTimeMillis) {
this.currentTimeMillis = currentTimeMillis;
}
public String getRole() {
return this.role;
}
public void setRole(String role) {
this.role = role;
}
public String getRoleId() {
return this.roleId;
}
public void setRoleId(String roleId) {
this.roleId = roleId;
}
public String getClientId() {
return this.clientId;
}
public void setClientId(String clientId) {
this.clientId = clientId;
}
}