diff --git a/spring-boot-service-template-common/src/main/java/com/lanyuanxiaoyao/service/template/common/exception/IdNotFoundException.java b/spring-boot-service-template-common/src/main/java/com/lanyuanxiaoyao/service/template/common/exception/IdNotFoundException.java new file mode 100644 index 0000000..21b9aad --- /dev/null +++ b/spring-boot-service-template-common/src/main/java/com/lanyuanxiaoyao/service/template/common/exception/IdNotFoundException.java @@ -0,0 +1,7 @@ +package com.lanyuanxiaoyao.service.template.common.exception; + +public class IdNotFoundException extends RuntimeException { + public IdNotFoundException(Long id) { + super("ID为 %d 的资源不存在".formatted(id)); + } +} diff --git a/spring-boot-service-template-common/src/main/java/com/lanyuanxiaoyao/service/template/common/exception/NotCollectionException.java b/spring-boot-service-template-common/src/main/java/com/lanyuanxiaoyao/service/template/common/exception/NotCollectionException.java new file mode 100644 index 0000000..b6fb1cc --- /dev/null +++ b/spring-boot-service-template-common/src/main/java/com/lanyuanxiaoyao/service/template/common/exception/NotCollectionException.java @@ -0,0 +1,7 @@ +package com.lanyuanxiaoyao.service.template.common.exception; + +public class NotCollectionException extends RuntimeException { + public NotCollectionException(String variable) { + super("变量 %s 不是集合".formatted(variable)); + } +} diff --git a/spring-boot-service-template-common/src/main/java/com/lanyuanxiaoyao/service/template/common/exception/NotComparableException.java b/spring-boot-service-template-common/src/main/java/com/lanyuanxiaoyao/service/template/common/exception/NotComparableException.java new file mode 100644 index 0000000..d6be277 --- /dev/null +++ b/spring-boot-service-template-common/src/main/java/com/lanyuanxiaoyao/service/template/common/exception/NotComparableException.java @@ -0,0 +1,7 @@ +package com.lanyuanxiaoyao.service.template.common.exception; + +public class NotComparableException extends RuntimeException { + public NotComparableException(String variable) { + super("变量 %s 不能比较".formatted(variable)); + } +} diff --git a/spring-boot-service-template-common/src/main/java/com/lanyuanxiaoyao/service/template/common/exception/NotStringException.java b/spring-boot-service-template-common/src/main/java/com/lanyuanxiaoyao/service/template/common/exception/NotStringException.java new file mode 100644 index 0000000..17a1274 --- /dev/null +++ b/spring-boot-service-template-common/src/main/java/com/lanyuanxiaoyao/service/template/common/exception/NotStringException.java @@ -0,0 +1,7 @@ +package com.lanyuanxiaoyao.service.template.common.exception; + +public class NotStringException extends RuntimeException { + public NotStringException(String variable) { + super("变量 %s 不是字符串".formatted(variable)); + } +} diff --git a/spring-boot-service-template-jpa/src/main/java/com/lanyuanxiaoyao/service/template/jpa/service/SimpleServiceSupport.java b/spring-boot-service-template-jpa/src/main/java/com/lanyuanxiaoyao/service/template/jpa/service/SimpleServiceSupport.java index 20cf6d1..4f95960 100644 --- a/spring-boot-service-template-jpa/src/main/java/com/lanyuanxiaoyao/service/template/jpa/service/SimpleServiceSupport.java +++ b/spring-boot-service-template-jpa/src/main/java/com/lanyuanxiaoyao/service/template/jpa/service/SimpleServiceSupport.java @@ -1,6 +1,10 @@ package com.lanyuanxiaoyao.service.template.jpa.service; import com.lanyuanxiaoyao.service.template.common.controller.Query; +import com.lanyuanxiaoyao.service.template.common.exception.IdNotFoundException; +import com.lanyuanxiaoyao.service.template.common.exception.NotCollectionException; +import com.lanyuanxiaoyao.service.template.common.exception.NotComparableException; +import com.lanyuanxiaoyao.service.template.common.exception.NotStringException; import com.lanyuanxiaoyao.service.template.common.helper.ObjectHelper; import com.lanyuanxiaoyao.service.template.common.service.Page; import com.lanyuanxiaoyao.service.template.common.service.SimpleService; @@ -594,72 +598,4 @@ public abstract class SimpleServiceSupport implemen repository.deleteBatchByIds(ids); } } - - /** - * ID未找到异常 - *

- * 当根据ID查询实体但实体不存在时抛出此异常。 - *

- */ - public static final class IdNotFoundException extends RuntimeException { - /** - * 构造函数(带ID参数) - * - * @param id 实体ID - */ - public IdNotFoundException(Long id) { - super("ID为 %d 的资源不存在".formatted(id)); - } - } - - /** - * 不可比较异常 - *

- * 当尝试对不可比较的字段或值执行比较操作时抛出此异常。 - *

- */ - public static final class NotComparableException extends RuntimeException { - /** - * 构造函数 - * - * @param variable 变量名称 - */ - public NotComparableException(String variable) { - super("变量 %s 不能比较".formatted(variable)); - } - } - - /** - * 非集合异常 - *

- * 当尝试对非集合类型的字段或值执行集合操作时抛出此异常。 - *

- */ - public static final class NotCollectionException extends RuntimeException { - /** - * 构造函数 - * - * @param variable 变量名称 - */ - public NotCollectionException(String variable) { - super("变量 %s 不是集合".formatted(variable)); - } - } - - /** - * 非字符串异常 - *

- * 当尝试对非字符串类型的字段或值执行字符串操作时抛出此异常。 - *

- */ - public static final class NotStringException extends RuntimeException { - /** - * 构造函数 - * - * @param variable 变量名称 - */ - public NotStringException(String variable) { - super("变量 %s 不是字符串".formatted(variable)); - } - } } \ No newline at end of file