com.gccloud.starter.common.utils.TokenUtils Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of gc-starter-common Show documentation
Show all versions of gc-starter-common Show documentation
几乎所有的模块都依赖该模块,该模块中引入了一些常用工具类、通用的bean、全局异常处理、常量定义等
package com.gccloud.starter.common.utils;
import org.apache.commons.lang3.StringUtils;
import javax.servlet.http.HttpServletRequest;
/**
* @author liuchengbiao
* @date 2020-07-16 16:51
*/
public class TokenUtils {
/**
* 获取token
*
* @param request
* @return
*/
public static String getToken(HttpServletRequest request) {
// 从header中获取token
String token = request.getHeader("token");
if (StringUtils.isBlank(token)) {
token = CookieUtils.getValue(request, "token");
} else if (StringUtils.isBlank(token)) {
// 如果header中不存在token,则从参数中获取token
token = request.getParameter("token");
}
return token;
}
}