From 8244b5dbdf458c63904b23983213e958d79b696b Mon Sep 17 00:00:00 2001 From: lanyuanxiaoyao Date: Thu, 21 Aug 2025 10:43:21 +0800 Subject: [PATCH] =?UTF-8?q?perf:=20=E7=AE=80=E5=8C=96=E4=BB=A3=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../template/service/SimpleService.java | 5 ---- .../service/SimpleServiceSupport.java | 26 ++----------------- 2 files changed, 2 insertions(+), 29 deletions(-) diff --git a/src/main/java/com/lanyuanxiaoyao/service/template/service/SimpleService.java b/src/main/java/com/lanyuanxiaoyao/service/template/service/SimpleService.java index 697fce2..4e16360 100644 --- a/src/main/java/com/lanyuanxiaoyao/service/template/service/SimpleService.java +++ b/src/main/java/com/lanyuanxiaoyao/service/template/service/SimpleService.java @@ -3,7 +3,6 @@ package com.lanyuanxiaoyao.service.template.service; import com.lanyuanxiaoyao.service.template.controller.Query; import com.lanyuanxiaoyao.service.template.entity.SimpleEntity; import java.util.List; -import java.util.Optional; import java.util.Set; import org.springframework.data.domain.Page; @@ -18,13 +17,9 @@ public interface SimpleService { Page list(Query query) throws Exception; - Optional detailOptional(Long id) throws Exception; - ENTITY detail(Long id) throws Exception; ENTITY detailOrThrow(Long id) throws Exception; - ENTITY detailOrNull(Long id) throws Exception; - void remove(Long id) throws Exception; } diff --git a/src/main/java/com/lanyuanxiaoyao/service/template/service/SimpleServiceSupport.java b/src/main/java/com/lanyuanxiaoyao/service/template/service/SimpleServiceSupport.java index ef7ea6f..86e3ed9 100644 --- a/src/main/java/com/lanyuanxiaoyao/service/template/service/SimpleServiceSupport.java +++ b/src/main/java/com/lanyuanxiaoyao/service/template/service/SimpleServiceSupport.java @@ -493,8 +493,7 @@ public abstract class SimpleServiceSupport implemen * @param id 实体ID * @return Optional 返回实体详情的Optional包装 */ - @Override - public Optional detailOptional(Long id) { + private Optional detailOptional(Long id) { if (ObjectHelper.isNull(id)) { return Optional.empty(); } @@ -520,7 +519,7 @@ public abstract class SimpleServiceSupport implemen */ @Override public ENTITY detail(Long id) { - return detailOrNull(id); + return detailOptional(id).orElse(null); } /** @@ -538,20 +537,6 @@ public abstract class SimpleServiceSupport implemen return detailOptional(id).orElseThrow(() -> new IdNotFoundException(id)); } - /** - * 根据ID获取实体详情,不存在时返回null - *

- * 与[detail](file:///Users/lanyuanxiaoyao/Project/IdeaProjects/spring-boot-service-template/src/main/java/com/lanyuanxiaoyao/service/template/service/SimpleService.java#L21-L21)方法功能相同。 - *

- * - * @param id 实体ID - * @return ENTITY 返回实体详情,不存在时返回null - */ - @Override - public ENTITY detailOrNull(Long id) { - return detailOptional(id).orElse(null); - } - /** * 根据ID删除实体 *

@@ -576,13 +561,6 @@ public abstract class SimpleServiceSupport implemen *

*/ public static final class IdNotFoundException extends RuntimeException { - /** - * 构造函数(无参) - */ - public IdNotFoundException() { - super("资源不存在"); - } - /** * 构造函数(带ID参数) *