HttpAspectUtil.java 907 Bytes
Newer Older
yanzg's avatar
yanzg committed
1 2
package com.yanzuoguang.cloud.aop;

yanzg's avatar
yanzg committed
3
import com.yanzuoguang.util.exception.CodeException;
yanzg's avatar
yanzg committed
4 5 6 7 8 9 10
import org.springframework.web.context.request.RequestContextHolder;
import org.springframework.web.context.request.ServletRequestAttributes;

import javax.servlet.http.HttpServletRequest;

/**
 * 虚拟拦截类
yanzg's avatar
yanzg committed
11
 * @author 颜佐光
yanzg's avatar
yanzg committed
12
 */
yanzg's avatar
yanzg committed
13
public class HttpAspectUtil {
yanzg's avatar
yanzg committed
14 15 16 17 18 19

    /**
     * 获取 http request
     *
     * @return
     */
yanzg's avatar
yanzg committed
20
    public static HttpServletRequest getRequest() {
yanzg's avatar
yanzg committed
21 22 23 24 25
        ServletRequestAttributes attributes = (ServletRequestAttributes) RequestContextHolder.getRequestAttributes();
        if (attributes == null) {
            throw new CodeException("监视错误");
        }
        return attributes.getRequest();
yanzg's avatar
yanzg committed
26 27 28 29 30 31 32
    }

    /**
     * 获取 http request url
     *
     * @return
     */
yanzg's avatar
yanzg committed
33
    public static String getHttpRequestUrl() {
yanzg's avatar
yanzg committed
34 35 36
        return getRequest().getServletPath();
    }
}