RequestUtil工具类方法补充
This commit is contained in:
@@ -2,6 +2,9 @@ package com.njcn.web.utils;
|
||||
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import cn.hutool.extra.spring.SpringUtil;
|
||||
import cn.hutool.json.JSON;
|
||||
import cn.hutool.json.JSONObject;
|
||||
import cn.hutool.json.JSONUtil;
|
||||
import com.njcn.common.bean.CustomCacheUtil;
|
||||
import com.njcn.common.pojo.constant.SecurityConstants;
|
||||
import com.njcn.common.utils.JwtUtil;
|
||||
@@ -30,6 +33,16 @@ public class RequestUtil {
|
||||
return accessToken;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取当前请求的用户IP
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public static String getUserIp() {
|
||||
HttpServletRequest request = HttpServletUtil.getRequest();
|
||||
return request.getRemoteAddr();
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取当前登录用户的ID
|
||||
*
|
||||
@@ -45,6 +58,20 @@ public class RequestUtil {
|
||||
return userId;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取当前登录用户的用户名
|
||||
* @return 若成功,返回当前登录用户的用户名;若失败,返回null
|
||||
*/
|
||||
public static String getUserName(){
|
||||
String userJson = getUserJson();
|
||||
String username = null;
|
||||
if (StrUtil.isNotBlank(userJson)) {
|
||||
JSONObject obj = JSONUtil.parseObj(userJson);
|
||||
username = obj.getStr("username");
|
||||
}
|
||||
return username;
|
||||
}
|
||||
|
||||
/**
|
||||
* 从缓冲中获取当前登录用户的JSON格式的用户信息
|
||||
* @return 若成功,返回当前登录用户的JSON格式的用户信息;若失败,返回null
|
||||
|
||||
Reference in New Issue
Block a user