UserUtils.java
1004 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
package com.glsx.common.utils;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import com.glsx.common.constants.Constants;
/**
*
* @Title UserUtils.java
* @Package com.glsx.common.utils
* @Description TODO 获取当前用户工具类
* @author zhanghj
* @date 2019年2月12日 上午11:35:30
* @version 1.0.0
*/
public class UserUtils {
private static final Logger LOGGER = LoggerFactory.getLogger(UserUtils.class.getName());
public static String getUserName(HttpServletRequest request) {
HttpSession session = request.getSession();
String username = (String) session.getAttribute(Constants.SESSION_USERNAME_KEY);
return username;
}
public static Integer getUserId(HttpServletRequest request) {
HttpSession session = request.getSession();
Integer userId = (Integer)session.getAttribute(Constants.SESSION_USERID_KEY);
return userId;
}
}