xm
2024-06-14 722af26bc6fec32bb289b1df51a9016a4935610f
提交 | 用户 | 时间
722af2 1 package com.dl.framework.config;
X 2
3 import com.dl.common.utils.ServletUtils;
4 import org.springframework.stereotype.Component;
5
6 import javax.servlet.http.HttpServletRequest;
7
8 /**
9  * 服务相关配置
10  *
11  * @author dl
12  */
13 @Component
14 public class ServerConfig
15 {
16     /**
17      * 获取完整的请求路径,包括:域名,端口,上下文访问路径
18      *
19      * @return 服务地址
20      */
21     public String getUrl()
22     {
23         HttpServletRequest request = ServletUtils.getRequest();
24         return getDomain(request);
25     }
26
27     public static String getDomain(HttpServletRequest request)
28     {
29         StringBuffer url = request.getRequestURL();
30         String contextPath = request.getServletContext().getContextPath();
31         return url.delete(url.length() - request.getRequestURI().length(), url.length()).append(contextPath).toString();
32     }
33 }