From 3c4fee1db116c11d4f04727cfe076d7c94daeaf2 Mon Sep 17 00:00:00 2001 From: yanzhaofeige <yanzhaofeige@qq.com> Date: Mon, 30 Sep 2024 12:10:57 +0800 Subject: [PATCH] init --- cpzidc-framework/src/main/java/com/odcc/cpzidc/framework/config/ServerConfig.java | 32 ++++++++++++++++++++++++++++++++ 1 files changed, 32 insertions(+), 0 deletions(-) diff --git a/cpzidc-framework/src/main/java/com/odcc/cpzidc/framework/config/ServerConfig.java b/cpzidc-framework/src/main/java/com/odcc/cpzidc/framework/config/ServerConfig.java new file mode 100644 index 0000000..d1a2047 --- /dev/null +++ b/cpzidc-framework/src/main/java/com/odcc/cpzidc/framework/config/ServerConfig.java @@ -0,0 +1,32 @@ +package com.odcc.cpzidc.framework.config; + +import javax.servlet.http.HttpServletRequest; +import org.springframework.stereotype.Component; +import com.odcc.cpzidc.common.utils.ServletUtils; + +/** + * 服务相关配置 + * + * @author ruoyi + */ +@Component +public class ServerConfig +{ + /** + * 获取完整的请求路径,包括:域名,端口,上下文访问路径 + * + * @return 服务地址 + */ + public String getUrl() + { + HttpServletRequest request = ServletUtils.getRequest(); + return getDomain(request); + } + + public static String getDomain(HttpServletRequest request) + { + StringBuffer url = request.getRequestURL(); + String contextPath = request.getServletContext().getContextPath(); + return url.delete(url.length() - request.getRequestURI().length(), url.length()).append(contextPath).toString(); + } +} -- Gitblit v1.9.3