Javax.ws.rs.BadRequestExcection在Spring Rest中不起作用

问题描述 投票:0回答:1

在restEasy中我使用了这个BadRequestExcrption来抛出错误但是在Spring Rest中它没有用。请指定在Spring Rest中抛出400错误的任何方法。

rest spring-boot spring-restcontroller spring-rest
1个回答
0
投票

制作你自己的BadRequestException课并扔掉它。

这是一个例子:

@ResponseStatus(HttpStatus.BAD_REQUEST)
public class BadRequestException extends RuntimeException{

  public BadRequestException() {
      super();
  }

  public BadRequestException(final String message, final Throwable cause) {
      super(message, cause);
  }

  public BadRequestException(final String message) {
      super(message);
  }

  public BadRequestException(final Throwable cause) {
      super(cause);
  }
}

您可以在@ResponseStatus中指定自己的状态代码

© www.soinside.com 2019 - 2024. All rights reserved.