From ac557ce7fd11e1a3486a756cdba008d67eb32fca Mon Sep 17 00:00:00 2001 From: zhou-hao Date: Wed, 19 Aug 2020 15:19:22 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96=E5=BC=82=E5=B8=B8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../hswebframework/web/exception/NotFoundException.java | 8 +++++--- .../hswebframework/web/exception/ValidationException.java | 8 ++++++++ 2 files changed, 13 insertions(+), 3 deletions(-) diff --git a/hsweb-core/src/main/java/org/hswebframework/web/exception/NotFoundException.java b/hsweb-core/src/main/java/org/hswebframework/web/exception/NotFoundException.java index b63bf1d48..504504cce 100644 --- a/hsweb-core/src/main/java/org/hswebframework/web/exception/NotFoundException.java +++ b/hsweb-core/src/main/java/org/hswebframework/web/exception/NotFoundException.java @@ -18,9 +18,11 @@ package org.hswebframework.web.exception; -/** - * - */ +import org.springframework.http.HttpStatus; +import org.springframework.web.bind.annotation.ResponseStatus; + + +@ResponseStatus(HttpStatus.NOT_FOUND) public class NotFoundException extends BusinessException { public NotFoundException(String message) { super(message, 404); diff --git a/hsweb-core/src/main/java/org/hswebframework/web/exception/ValidationException.java b/hsweb-core/src/main/java/org/hswebframework/web/exception/ValidationException.java index 44e7852d5..da0af918f 100644 --- a/hsweb-core/src/main/java/org/hswebframework/web/exception/ValidationException.java +++ b/hsweb-core/src/main/java/org/hswebframework/web/exception/ValidationException.java @@ -3,14 +3,18 @@ package org.hswebframework.web.exception; import lombok.AllArgsConstructor; import lombok.Getter; import lombok.Setter; +import org.springframework.http.HttpStatus; +import org.springframework.web.bind.annotation.ResponseStatus; import javax.validation.ConstraintViolation; import java.util.ArrayList; +import java.util.Collections; import java.util.List; import java.util.Set; @Getter @Setter +@ResponseStatus(HttpStatus.BAD_REQUEST) public class ValidationException extends BusinessException { private List details; @@ -19,6 +23,10 @@ public class ValidationException extends BusinessException { super(message); } + public ValidationException(String property, String message) { + this(message, Collections.singletonList(new Detail(property, message, null))); + } + public ValidationException(String message, List details) { super(message); this.details = details;