1 回答
TA贡献1809条经验 获得超8个赞
您希望errorIdanderrorMsg作为 ValidationException 类的字段,就像您对普通类所做的那样。
public class ValidationException extends RuntimeException {
private String errorId;
private String errorMsg;
public validationException(String errorId, String errorMsg) {
this.errorId = errorId;
this.errorMsg = errorMsg;
}
public String getErrorId() {
return this.errorId;
}
public String getErrorMsg() {
return this.errorMsg;
}
}
在您的 GlobalExceptionHandler 中:
@ExceptionHandler(ValidationException.class)
public ResponseEntity<SomeObject> handleValidationException(ValidationException ex) {
// here you can do whatever you like
ex.getErrorId();
ex.getErrorMsg();
}
添加回答
举报