diff --git a/pom.xml b/pom.xml
index eda9bcc..348d82c 100644
--- a/pom.xml
+++ b/pom.xml
@@ -46,6 +46,12 @@
org.springframework.boot
spring-boot-starter-aop
+
+
+ com.github.xiaoymin
+ knife4j-openapi2-spring-boot-starter
+ 4.4.0
+
diff --git a/src/main/java/com/huangge1199/picture/common/HttpStatus.java b/src/main/java/com/huangge1199/picture/common/HttpStatus.java
new file mode 100644
index 0000000..ae5beaa
--- /dev/null
+++ b/src/main/java/com/huangge1199/picture/common/HttpStatus.java
@@ -0,0 +1,94 @@
+package com.huangge1199.picture.common;
+
+/**
+ * 返回状态码
+ *
+ * @author ruoyi
+ */
+public class HttpStatus
+{
+ /**
+ * 操作成功
+ */
+ public static final int SUCCESS = 200;
+
+ /**
+ * 对象创建成功
+ */
+ public static final int CREATED = 201;
+
+ /**
+ * 请求已经被接受
+ */
+ public static final int ACCEPTED = 202;
+
+ /**
+ * 操作已经执行成功,但是没有返回数据
+ */
+ public static final int NO_CONTENT = 204;
+
+ /**
+ * 资源已被移除
+ */
+ public static final int MOVED_PERM = 301;
+
+ /**
+ * 重定向
+ */
+ public static final int SEE_OTHER = 303;
+
+ /**
+ * 资源没有被修改
+ */
+ public static final int NOT_MODIFIED = 304;
+
+ /**
+ * 参数列表错误(缺少,格式不匹配)
+ */
+ public static final int BAD_REQUEST = 400;
+
+ /**
+ * 未授权
+ */
+ public static final int UNAUTHORIZED = 401;
+
+ /**
+ * 访问受限,授权过期
+ */
+ public static final int FORBIDDEN = 403;
+
+ /**
+ * 资源,服务未找到
+ */
+ public static final int NOT_FOUND = 404;
+
+ /**
+ * 不允许的http方法
+ */
+ public static final int BAD_METHOD = 405;
+
+ /**
+ * 资源冲突,或者资源被锁
+ */
+ public static final int CONFLICT = 409;
+
+ /**
+ * 不支持的数据,媒体类型
+ */
+ public static final int UNSUPPORTED_TYPE = 415;
+
+ /**
+ * 系统内部错误
+ */
+ public static final int ERROR = 500;
+
+ /**
+ * 接口未实现
+ */
+ public static final int NOT_IMPLEMENTED = 501;
+
+ /**
+ * 系统警告消息
+ */
+ public static final int WARN = 601;
+}
diff --git a/src/main/java/com/huangge1199/picture/common/R.java b/src/main/java/com/huangge1199/picture/common/R.java
index 8dfb9db..90b1a7e 100644
--- a/src/main/java/com/huangge1199/picture/common/R.java
+++ b/src/main/java/com/huangge1199/picture/common/R.java
@@ -1,35 +1,113 @@
package com.huangge1199.picture.common;
-import com.huangge1199.picture.exception.ErrorCode;
-
import java.io.Serializable;
/**
- * R
- * 返回响应
+ * 响应信息主体
*
- * @author huangge1199
- * @since 2025/6/27 16:24:58
+ * @author ruoyi
*/
public class R implements Serializable {
+ private static final long serialVersionUID = 1L;
+
+ /**
+ * 成功
+ */
+ public static final int SUCCESS = HttpStatus.SUCCESS;
+
+ /**
+ * 失败
+ */
+ public static final int FAIL = HttpStatus.ERROR;
private int code;
+ private String msg;
+
private T data;
- private String message;
+ public static R ok() {
+ return restResult(null, SUCCESS, "操作成功");
+ }
- public R(int code, T data, String message) {
+ public static R ok(T data) {
+ return restResult(data, SUCCESS, "操作成功");
+ }
+
+ public static R ok(T data, String msg) {
+ return restResult(data, SUCCESS, msg);
+ }
+
+ public static R fail() {
+ return restResult(null, FAIL, "操作失败");
+ }
+
+ public static R fail(String msg) {
+ return restResult(null, FAIL, msg);
+ }
+
+ public static R fail(Exception e) {
+ String msg = e.getMessage();
+ if (e.getCause() != null) {
+ msg = e.getCause().getMessage();
+ } else {
+ return restResult(null, FAIL, msg);
+ }
+ if (e.getCause().getCause() != null) {
+ msg = e.getCause().getCause().getMessage();
+ }
+ return restResult(null, FAIL, msg);
+ }
+
+ public static R fail(T data) {
+ return restResult(data, FAIL, "操作失败");
+ }
+
+ public static R fail(T data, String msg) {
+ return restResult(data, FAIL, msg);
+ }
+
+ public static R fail(int code, String msg) {
+ return restResult(null, code, msg);
+ }
+
+ private static R restResult(T data, int code, String msg) {
+ R apiResult = new R<>();
+ apiResult.setCode(code);
+ apiResult.setData(data);
+ apiResult.setMsg(msg);
+ return apiResult;
+ }
+
+ public int getCode() {
+ return code;
+ }
+
+ public void setCode(int code) {
this.code = code;
+ }
+
+ public String getMsg() {
+ return msg;
+ }
+
+ public void setMsg(String msg) {
+ this.msg = msg;
+ }
+
+ public T getData() {
+ return data;
+ }
+
+ public void setData(T data) {
this.data = data;
- this.message = message;
}
- public R(int code, T data) {
- this(code, data, "");
+ public static Boolean isError(R ret) {
+ return !isSuccess(ret);
}
- public R(ErrorCode errorCode) {
- this(errorCode.getCode(), null, errorCode.getMessage());
+ public static Boolean isSuccess(R ret) {
+ return R.SUCCESS == ret.getCode();
}
}
diff --git a/src/main/java/com/huangge1199/picture/controller/MainController.java b/src/main/java/com/huangge1199/picture/controller/MainController.java
new file mode 100644
index 0000000..c137fc9
--- /dev/null
+++ b/src/main/java/com/huangge1199/picture/controller/MainController.java
@@ -0,0 +1,26 @@
+package com.huangge1199.picture.controller;
+
+import com.huangge1199.picture.common.R;
+import org.springframework.web.bind.annotation.GetMapping;
+import org.springframework.web.bind.annotation.RequestMapping;
+import org.springframework.web.bind.annotation.RestController;
+
+/**
+ * MainController
+ *
+ * @author huangge1199
+ * @since 2025/6/28 16:29:11
+ */
+@RestController
+@RequestMapping("/")
+public class MainController {
+
+ /**
+ * 健康检查
+ */
+ @GetMapping("/health")
+ public R> health() {
+ return R.ok();
+ }
+}
+
diff --git a/src/main/resources/application.yml b/src/main/resources/application.yml
index f3ea53d..2c904c8 100644
--- a/src/main/resources/application.yml
+++ b/src/main/resources/application.yml
@@ -21,3 +21,14 @@ mybatis-plus:
logic-delete-field: isDelete # 全局逻辑删除的实体字段名
logic-delete-value: 1 # 逻辑已删除值(默认为 1)
logic-not-delete-value: 0 # 逻辑未删除值(默认为 0)
+# 接口文档配置
+knife4j:
+ enable: true
+ openapi:
+ title: "接口文档"
+ version: 1.0
+ group:
+ default:
+ api-rule: package
+ api-rule-resources:
+ - com.huangge1199.picture.controller