Interface ResultCode

All Known Implementing Classes:
CommonResultCode

public interface ResultCode
Result Code Interface 响应码接口

Defines the contract for result codes used in API responses.

定义API响应中使用的响应码契约。

Features | 主要功能:

  • Unified code format - 统一的响应码格式
  • Extensible via enum - 可通过枚举扩展
  • HTTP status mapping - HTTP状态码映射

Usage Examples | 使用示例:

ResultCode custom = ResultCode.of("E001", "Not found", 404);
String code = custom.getCode();
boolean ok = custom.isSuccess();

Security | 安全性:

  • Thread-safe: Yes (interface with stateless defaults) - 是(带无状态默认方法的接口)
  • Null-safe: No (code and message should not be null) - 否(响应码和消息不应为null)
Since:
JDK 25, opencode-base-web V1.0.0
Author:
Leon Soo www.LeonSoo.com
See Also:
  • Method Summary

    Modifier and Type
    Method
    Description
    Get the code 获取响应码
    default int
    Get the HTTP status code 获取HTTP状态码
    Get the message 获取响应消息
    default boolean
    Check if success 检查是否成功
    static ResultCode
    of(String code, String message)
    Create custom result code 创建自定义响应码
    static ResultCode
    of(String code, String message, int httpStatus)
    Create custom result code with HTTP status 创建带HTTP状态的自定义响应码
  • Method Details

    • getCode

      String getCode()
      Get the code 获取响应码
      Returns:
      the code | 响应码
    • getMessage

      String getMessage()
      Get the message 获取响应消息
      Returns:
      the message | 响应消息
    • getHttpStatus

      default int getHttpStatus()
      Get the HTTP status code 获取HTTP状态码
      Returns:
      the HTTP status code | HTTP状态码
    • isSuccess

      default boolean isSuccess()
      Check if success 检查是否成功
      Returns:
      true if success | 如果成功返回true
    • of

      static ResultCode of(String code, String message)
      Create custom result code 创建自定义响应码
      Parameters:
      code - the code | 响应码
      message - the message | 响应消息
      Returns:
      result code instance | 响应码实例
    • of

      static ResultCode of(String code, String message, int httpStatus)
      Create custom result code with HTTP status 创建带HTTP状态的自定义响应码
      Parameters:
      code - the code | 响应码
      message - the message | 响应消息
      httpStatus - the HTTP status | HTTP状态码
      Returns:
      result code instance | 响应码实例