fix javadoc warning

This commit is contained in:
Timi
2026-01-04 17:27:36 +08:00
parent ec7f4ecaa9
commit a9156e07f4
32 changed files with 587 additions and 11 deletions

View File

@@ -42,6 +42,12 @@ public class TimiSpring {
private static final Logger log = LoggerFactory.getLogger(TimiSpring.class);
private static final Gson GSON = new Gson();
/**
* 工具类禁止实例化
*/
private TimiSpring() {
}
/**
* 回调数据
*
@@ -102,24 +108,50 @@ public class TimiSpring {
return getServletRequestAttributes().getRequest();
}
/**
* 获取请求域名
*
* @return 请求域名
*/
public static String getDomain() {
return getRequest().getServerName();
}
/**
* 获取完整域名(含协议与端口)
*
* @return 完整域名
*/
public static String getFullDomain() {
HttpServletRequest req = getRequest();
String port = req.getServerPort() == 80 || req.getServerPort() == 443 ? "" : ":" + req.getServerPort();
return "%s://%s%s".formatted(req.getScheme(), getDomain(), port);
}
/**
* 获取请求 URL
*
* @return 请求 URL
*/
public static String getURL() {
return getRequest().getRequestURL().toString();
}
/**
* 获取请求 URI
*
* @return 请求 URI
*/
public static String getURI() {
return getRequest().getRequestURI();
}
/**
* 从 URI 指定标记开始截取
*
* @param flag 标记
* @return 截取后的 URI
*/
public static String cutURIStartAt(String flag) {
int indexOf = getURI().indexOf(flag);
TimiException.requiredTrue(-1 < indexOf, "not found flag: %s".formatted(flag));
@@ -315,14 +347,31 @@ public class TimiSpring {
return getRequest().getParameterValues(key);
}
/**
* 添加 Cookie
*
* @param cookie Cookie
*/
public static void addCookie(Cookie cookie) {
getResponse().addCookie(cookie);
}
/**
* 添加 Cookie
*
* @param key 键
* @param value 值
*/
public static void addCookie(String key, String value) {
addCookie(new Cookie(key, value));
}
/**
* 获取 Cookie
*
* @param key 键
* @return Cookie
*/
public static Cookie getCookie(String key) {
Cookie[] cookies = getRequest().getCookies();
if (cookies == null) {
@@ -345,11 +394,17 @@ public class TimiSpring {
return TimiJava.firstNotEmpty(getHeader("Token"), getHeader("token"), getRequestArg("token"), getRequestArg("Token"));
}
/**
* 获取原始语言头
*
* @return 语言头
*/
public static String getLanguageRaw() {
return getHeader("Accept-Language");
}
/**
* 获取客户端地区语言
*
* @return 客户端地区语言
*/
@@ -399,10 +454,22 @@ public class TimiSpring {
return "0:0:0:0:0:0:0:1".equals(ip) ? "127.0.0.1" : ip;
}
/**
* 是否本地 IP
*
* @return true 为本地 IP
*/
public static boolean isLocalIP() {
return getRequestIP().startsWith("127");
}
/**
* 解析 Range 请求范围
*
* @param fileLength 文件长度
* @return 请求范围
* @throws IOException IO 异常
*/
public static RequestRange requestRange(long fileLength) throws IOException {
HttpServletResponse resp = getResponse();