All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.gccloud.starter.common.utils.TokenUtils Maven / Gradle / Ivy

Go to download

几乎所有的模块都依赖该模块,该模块中引入了一些常用工具类、通用的bean、全局异常处理、常量定义等

There is a newer version: 2.3.0.RELEASE
Show newest version
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;
    }

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy