diff --git a/spring-boot-service-template-common/src/main/java/com/lanyuanxiaoyao/service/template/common/controller/DetailController.java b/spring-boot-service-template-common/src/main/java/com/lanyuanxiaoyao/service/template/common/controller/DetailController.java deleted file mode 100644 index f065436..0000000 --- a/spring-boot-service-template-common/src/main/java/com/lanyuanxiaoyao/service/template/common/controller/DetailController.java +++ /dev/null @@ -1,27 +0,0 @@ -package com.lanyuanxiaoyao.service.template.common.controller; - -/** - * 详情控制器接口,用于定义统一的获取实体详情的接口规范 - * - *

- * 前端传入的JSON格式示例: - *

- * GET /detail/1
- * 
- *

- * - * @param 详情实体类型 - * @author lanyuanxiaoyao - */ -public interface DetailController { - String DETAIL = "/detail/{id}"; - - /** - * 根据ID获取实体详情 - * - * @param id 实体ID - * @return GlobalResponse 返回实体详情 - * @throws Exception 查询过程中可能抛出的异常 - */ - GlobalResponse detail(Long id) throws Exception; -} \ No newline at end of file diff --git a/spring-boot-service-template-common/src/main/java/com/lanyuanxiaoyao/service/template/common/controller/ListController.java b/spring-boot-service-template-common/src/main/java/com/lanyuanxiaoyao/service/template/common/controller/QueryController.java similarity index 79% rename from spring-boot-service-template-common/src/main/java/com/lanyuanxiaoyao/service/template/common/controller/ListController.java rename to spring-boot-service-template-common/src/main/java/com/lanyuanxiaoyao/service/template/common/controller/QueryController.java index d34a878..5d5c1d6 100644 --- a/spring-boot-service-template-common/src/main/java/com/lanyuanxiaoyao/service/template/common/controller/ListController.java +++ b/spring-boot-service-template-common/src/main/java/com/lanyuanxiaoyao/service/template/common/controller/QueryController.java @@ -3,7 +3,7 @@ package com.lanyuanxiaoyao.service.template.common.controller; import java.util.Map; /** - * 列表控制器接口,用于定义统一的获取实体列表的接口规范 + * 查询控制器接口,用于定义统一的查询实体详情和列表的接口规范 * *

* 前端传入的JSON格式示例: @@ -53,16 +53,17 @@ import java.util.Map; * *

* - * @param 列表项的实体类型 + * @param 查询结果的实体类型 * @author lanyuanxiaoyao */ -public interface ListController { +public interface QueryController { String LIST = "/list"; + String DETAIL = "/detail/{id}"; /** * 获取所有实体列表 * - * @return GlobalCrudResponse 返回实体列表 + * @return GlobalResponse> 返回实体列表 * @throws Exception 查询过程中可能抛出的异常 */ GlobalResponse> list() throws Exception; @@ -71,8 +72,17 @@ public interface ListController { * 根据查询条件获取实体列表 * * @param query 查询条件对象 - * @return GlobalCrudResponse 返回符合条件的实体列表 + * @return GlobalResponse> 返回符合条件的实体列表 * @throws Exception 查询过程中可能抛出的异常 */ GlobalResponse> list(Query query) 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/spring-boot-service-template-common/src/main/java/com/lanyuanxiaoyao/service/template/common/controller/SimpleController.java b/spring-boot-service-template-common/src/main/java/com/lanyuanxiaoyao/service/template/common/controller/SimpleController.java index 3dc771b..eb159fb 100644 --- a/spring-boot-service-template-common/src/main/java/com/lanyuanxiaoyao/service/template/common/controller/SimpleController.java +++ b/spring-boot-service-template-common/src/main/java/com/lanyuanxiaoyao/service/template/common/controller/SimpleController.java @@ -1,4 +1,4 @@ package com.lanyuanxiaoyao.service.template.common.controller; -public interface SimpleController extends SaveController, ListController, DetailController, RemoveController { +public interface SimpleController extends SaveController, QueryController, RemoveController { } diff --git a/spring-boot-service-template-common/src/main/java/com/lanyuanxiaoyao/service/template/common/service/QueryService.java b/spring-boot-service-template-common/src/main/java/com/lanyuanxiaoyao/service/template/common/service/QueryService.java new file mode 100644 index 0000000..9f02ad4 --- /dev/null +++ b/spring-boot-service-template-common/src/main/java/com/lanyuanxiaoyao/service/template/common/service/QueryService.java @@ -0,0 +1,65 @@ +package com.lanyuanxiaoyao.service.template.common.service; + +import com.lanyuanxiaoyao.service.template.common.controller.Query; +import java.util.List; +import java.util.Set; + +/** + * 查询服务接口,用于定义统一的查询实体详情和列表的服务规范 + * + * @param 实体类型 + * @author lanyuanxiaoyao + */ +public interface QueryService { + /** + * 根据ID获取实体详情 + * + * @param id 实体ID + * @return 实体详情 + * @throws Exception 查询过程中可能抛出的异常 + */ + ENTITY detail(Long id) throws Exception; + + /** + * 根据ID获取实体详情,如果不存在则抛出异常 + * + * @param id 实体ID + * @return 实体详情 + * @throws Exception 查询过程中可能抛出的异常 + */ + ENTITY detailOrThrow(Long id) throws Exception; + + /** + * 获取实体总数 + * + * @return 实体总数 + * @throws Exception 查询过程中可能抛出的异常 + */ + Long count() throws Exception; + + /** + * 获取所有实体列表 + * + * @return 实体列表 + * @throws Exception 查询过程中可能抛出的异常 + */ + List list() throws Exception; + + /** + * 根据ID集合获取实体列表 + * + * @param ids 实体ID集合 + * @return 实体列表 + * @throws Exception 查询过程中可能抛出的异常 + */ + List list(Set ids) throws Exception; + + /** + * 根据查询条件获取分页实体列表 + * + * @param query 查询条件对象 + * @return 分页实体列表 + * @throws Exception 查询过程中可能抛出的异常 + */ + Page list(Query query) throws Exception; +} \ No newline at end of file diff --git a/spring-boot-service-template-common/src/main/java/com/lanyuanxiaoyao/service/template/common/service/RemoveService.java b/spring-boot-service-template-common/src/main/java/com/lanyuanxiaoyao/service/template/common/service/RemoveService.java new file mode 100644 index 0000000..3505b95 --- /dev/null +++ b/spring-boot-service-template-common/src/main/java/com/lanyuanxiaoyao/service/template/common/service/RemoveService.java @@ -0,0 +1,25 @@ +package com.lanyuanxiaoyao.service.template.common.service; + +/** + * 删除服务接口,用于定义统一的删除实体对象的服务规范 + * + * @param 实体类型 + * @author lanyuanxiaoyao + */ +public interface RemoveService { + /** + * 根据ID删除实体对象 + * + * @param id 需要删除的实体ID + * @throws Exception 删除过程中可能抛出的异常 + */ + void remove(Long id) throws Exception; + + /** + * 批量删除实体对象 + * + * @param ids 需要删除的实体ID集合 + * @throws Exception 删除过程中可能抛出的异常 + */ + void remove(Iterable ids) throws Exception; +} \ No newline at end of file diff --git a/spring-boot-service-template-common/src/main/java/com/lanyuanxiaoyao/service/template/common/service/SaveService.java b/spring-boot-service-template-common/src/main/java/com/lanyuanxiaoyao/service/template/common/service/SaveService.java new file mode 100644 index 0000000..8bdcdf3 --- /dev/null +++ b/spring-boot-service-template-common/src/main/java/com/lanyuanxiaoyao/service/template/common/service/SaveService.java @@ -0,0 +1,26 @@ +package com.lanyuanxiaoyao.service.template.common.service; + +/** + * 保存服务接口,用于定义统一的保存实体对象的服务规范 + * + * @param 实体类型 + * @author lanyuanxiaoyao + */ +public interface SaveService { + /** + * 保存实体对象 + * + * @param entity 需要保存的实体对象 + * @return 保存后的实体ID + * @throws Exception 保存过程中可能抛出的异常 + */ + Long save(ENTITY entity) throws Exception; + + /** + * 批量保存实体对象 + * + * @param entities 需要保存的实体对象集合 + * @throws Exception 保存过程中可能抛出的异常 + */ + void save(Iterable entities) throws Exception; +} \ No newline at end of file diff --git a/spring-boot-service-template-common/src/main/java/com/lanyuanxiaoyao/service/template/common/service/SimpleService.java b/spring-boot-service-template-common/src/main/java/com/lanyuanxiaoyao/service/template/common/service/SimpleService.java index de02767..11df5c1 100644 --- a/spring-boot-service-template-common/src/main/java/com/lanyuanxiaoyao/service/template/common/service/SimpleService.java +++ b/spring-boot-service-template-common/src/main/java/com/lanyuanxiaoyao/service/template/common/service/SimpleService.java @@ -1,27 +1,4 @@ package com.lanyuanxiaoyao.service.template.common.service; -import com.lanyuanxiaoyao.service.template.common.controller.Query; -import java.util.List; -import java.util.Set; - -public interface SimpleService { - Long save(ENTITY entity) throws Exception; - - void save(Iterable entities) throws Exception; - - Long count() throws Exception; - - List list() throws Exception; - - List list(Set ids) throws Exception; - - Page list(Query query) throws Exception; - - ENTITY detail(Long id) throws Exception; - - ENTITY detailOrThrow(Long id) throws Exception; - - void remove(Long id) throws Exception; - - void remove(Iterable ids) throws Exception; +public interface SimpleService extends SaveService, QueryService, RemoveService { }