类 SohelpWeb

java.lang.Object
net.sohelp.boot.admin.core.web.SohelpWeb

@Component public class SohelpWeb extends Object
Web工具类,提供对HTTP请求、响应以及参数处理的相关功能。
从以下版本开始:
2024/7/9 16:48
作者:
AaronFung
  • 构造器详细资料

    • SohelpWeb

      public SohelpWeb()
  • 方法详细资料

    • getDefaultLanguage

      @Comment("\u83b7\u53d6\u5ba2\u6237\u7aef\u9ed8\u8ba4\u8bed\u8a00") public String getDefaultLanguage()
      获取客户端默认语言。

      优先从请求参数"lang"中获取;若未指定,则尝试解析 HTTP 请求头中的 Accept-Language 字段; 若仍无法确定,默认使用当前请求的本地化信息(Locale)构造语言标识符。

      返回:
      客户端默认语言字符串,格式如:"zh_CN"
    • getRequest

      @Comment("\u83b7\u53d6HttpServletRequest\u5bf9\u8c61") public jakarta.servlet.http.HttpServletRequest getRequest()
      获取当前线程绑定的 HttpServletRequest 对象。
      返回:
      当前请求对象
    • getResponse

      @Comment("HttpServletResponse\u5bf9\u8c61") public jakarta.servlet.http.HttpServletResponse getResponse()
      获取当前线程绑定的 HttpServletResponse 对象。
      返回:
      当前响应对象
    • setAttribute

      @Comment("\u8bbe\u7f6eRequest\u5c5e\u6027\u503c") public void setAttribute(String name, Object value)
      向当前请求中设置属性值。
      参数:
      name - 属性名称
      value - 属性值
    • requestAvailable

      @Comment("HttpServletRequest\u662f\u5426\u53ef\u7528") public boolean requestAvailable()
      检查当前线程是否绑定了有效的 HttpServletRequest。
      返回:
      true 表示可用,false 表示不可用
    • getParameterMap

      @Comment("\u83b7\u53d6URL\u53c2\u6570\u4e2d\u83b7\u53d6Map\u5f62\u5f0f\u7684\u6570\u636e\u96c6\uff0c\u5e76\u53ef\u4ee5\u6dfb\u52a0\u65b0\u7684\u53c2\u6570") public Map<String,Object> getParameterMap(@Comment("\u989d\u5916\u6dfb\u52a0\u65b0\u7684\u53c2\u6570") Map<String,Object> paramMap)
      将 URL 参数转换为 Map 形式的数据集,并可额外合并传入的新参数。
      参数:
      paramMap - 需要额外添加到结果中的键值对映射
      返回:
      包含所有参数的 Map 数据集合
    • getParameterMapByExclude

      @Comment("\u8fd4\u56de\u6392\u9664\u53c2\u6570\u5217\u8868") public Map<String,Object> getParameterMapByExclude(@Comment("\u6392\u9664\u5c5e\u6027\u540d\u5217\u8868") Map<String,Object> paramMap, @Comment("\u6392\u9664\u5c5e\u6027\u540d\u5217\u8868") List<String> excludePropertyNames)
      获取参数 Map 并移除指定的排除项。
      参数:
      paramMap - 要合并进来的附加参数
      excludePropertyNames - 需要被排除的属性名列表
      返回:
      过滤后的参数 Map
    • getParameterMapByInclude

      @Comment("\u8fd4\u56de\u5305\u62ec\u53c2\u6570\u5217\u8868") public Map<String,Object> getParameterMapByInclude(@Comment("\u5305\u62ec\u5c5e\u6027\u7684\u53c2\u6570") List<String> includePropertyNames)
      获取参数 Map 并仅保留指定的包含项。
      参数:
      includePropertyNames - 需要保留的属性名列表
      返回:
      过滤后只包含指定字段的参数 Map
    • getParameterMapByInclude

      @Comment("\u8fd4\u56de\u5305\u62ec\u53c2\u6570\u5217\u8868") public Map<String,Object> getParameterMapByInclude(@Comment("\u989d\u5916\u6dfb\u52a0\u7684\u5c5e\u6027\u503c") Map<String,Object> paramMap, @Comment("\u5305\u62ec\u5c5e\u6027\u7684\u53c2\u6570") List<String> includePropertyNames)
      获取参数 Map 并仅保留指定的包含项。
      参数:
      paramMap - 要合并进来的附加参数
      includePropertyNames - 需要保留的属性名列表
      返回:
      过滤后只包含指定字段的参数 Map
    • getAttributes

      @Comment("\u83b7\u53d6request\u4e2d\u83b7\u53d6\u5c5e\u6027Map") public Map<String,Object> getAttributes()
      获取请求中以特定前缀存储的自定义属性 Map。
      返回:
      自定义属性组成的 Map
    • out

      @Comment("\u8f93\u51fa\u5185\u5bb9") public void out(@Comment("\u8f93\u51fa\u5185\u5bb9") String content) throws IOException
      向客户端输出 HTML 内容。
      参数:
      content - 要输出的内容文本
      抛出:
      IOException - 如果写入失败抛出异常
    • setAttributes

      @Comment("\u628aMap\u6570\u636e\u8bbe\u7f6e\u5230Request\u7684\u5c5e\u6027\u4e2d") public void setAttributes(@Comment("\u5c5e\u6027Map") Map<String,Object> attributeMap)
      批量将 Map 中的数据作为属性存入当前请求对象中。
      参数:
      attributeMap - 属性键值对映射
    • getParameterMap

      public Map<String,Object> getParameterMap()
      获取 URL 查询参数并封装成 Map 格式。

      单个值直接保存为字符串,多值则保存为数组。 同时会合并通过 setAttributes(Map) 方法设置的自定义属性。

      返回:
      包含所有查询参数及自定义属性的 Map