diff --git a/src/main/java/com/lanyuanxiaoyao/service/template/controller/DetailController.java b/src/main/java/com/lanyuanxiaoyao/service/template/controller/DetailController.java
index b51060c..3adfd16 100644
--- a/src/main/java/com/lanyuanxiaoyao/service/template/controller/DetailController.java
+++ b/src/main/java/com/lanyuanxiaoyao/service/template/controller/DetailController.java
@@ -1,7 +1,5 @@
package com.lanyuanxiaoyao.service.template.controller;
-import com.lanyuanxiaoyao.service.template.controller.response.GlobalResponse;
-
/**
* 详情控制器接口,用于定义统一的获取实体详情的接口规范
*
@@ -16,14 +14,14 @@ import com.lanyuanxiaoyao.service.template.controller.response.GlobalResponse;
* @author lanyuanxiaoyao
*/
public interface DetailController {
- String DETAIL = "/detail/{id}";
+ String DETAIL = "/detail/{id}";
- /**
- * 根据ID获取实体详情
- *
- * @param id 实体ID
- * @return GlobalResponse 返回实体详情
- * @throws Exception 查询过程中可能抛出的异常
- */
- GlobalResponse detail(Long id) throws Exception;
+ /**
+ * 根据ID获取实体详情
+ *
+ * @param id 实体ID
+ * @return GlobalResponse 返回实体详情
+ * @throws Exception 查询过程中可能抛出的异常
+ */
+ GlobalResponse detail(Long id) throws Exception;
}
\ No newline at end of file
diff --git a/src/main/java/com/lanyuanxiaoyao/service/template/controller/GlobalResponse.java b/src/main/java/com/lanyuanxiaoyao/service/template/controller/GlobalResponse.java
new file mode 100644
index 0000000..e1575fe
--- /dev/null
+++ b/src/main/java/com/lanyuanxiaoyao/service/template/controller/GlobalResponse.java
@@ -0,0 +1,77 @@
+package com.lanyuanxiaoyao.service.template.controller;
+
+import java.util.Map;
+import lombok.Getter;
+import lombok.Setter;
+import lombok.ToString;
+
+@Setter
+@Getter
+@ToString
+public class GlobalResponse {
+ private static final int SUCCESS_STATUS = 0;
+ private static final int ERROR_STATUS = 500;
+ private static final String SUCCESS_MESSAGE = "OK";
+ private static final String ERROR_MESSAGE = "ERROR";
+ private Integer status;
+ private String message;
+ private T data;
+
+ private GlobalResponse() {
+ this(SUCCESS_STATUS, SUCCESS_MESSAGE, null);
+ }
+
+ private GlobalResponse(Integer status, String message) {
+ this(status, message, null);
+ }
+
+ private GlobalResponse(Integer status, String message, T data) {
+ this.status = status;
+ this.message = message;
+ this.data = data;
+ }
+
+ public static GlobalResponse
*
- * @param 实体类型,必须继承SimpleEntity
- * @param 保存项类型
- * @param 列表项类型
+ * @param 实体类型,必须继承SimpleEntity
+ * @param 保存项类型
+ * @param 列表项类型
* @param 详情项类型
* @author lanyuanxiaoyao
*/
@Slf4j
public abstract class SimpleControllerSupport implements SimpleController {
- protected final SimpleServiceSupport service;
+ protected final SimpleServiceSupport service;
- /**
- * 构造函数
- *
- * @param service 简单服务支持类实例
- */
- public SimpleControllerSupport(SimpleServiceSupport service) {
- this.service = service;
+ /**
+ * 构造函数
+ *
+ * @param service 简单服务支持类实例
+ */
+ public SimpleControllerSupport(SimpleServiceSupport service) {
+ this.service = service;
+ }
+
+ /**
+ * 保存实体对象
+ *
+ * @param item 需要保存的项
+ * @return GlobalResponse 返回保存后的实体ID
+ * @throws Exception 保存过程中可能抛出的异常
+ */
+ @PostMapping(SAVE)
+ @Override
+ public GlobalResponse save(@RequestBody SAVE_ITEM item) throws Exception {
+ var mapper = saveItemMapper();
+ return GlobalResponse.responseSuccess(service.save(mapper.apply(item)));
+ }
+
+ /**
+ * 获取所有实体列表
+ *
+ * @return GlobalCrudResponse 返回实体列表
+ * @throws Exception 查询过程中可能抛出的异常
+ */
+ @GetMapping(LIST)
+ @Override
+ public GlobalResponse