请求参数中枚举的异常处理程序



我有一个Get请求:allTopic
它输入一个filterCriteria自定义对象,该对象包含多个字段,其中一个是名为Role的枚举,它是学生或教师

还有更多不同的API调用,使用不同的枚举。所以我想创建@controllerAdvice来处理所有这些。

我需要的帮助

  1. 要放入Getneneneba API控制器函数头中的注释
  2. 要放入filterCriteria类中的注释
  3. 在@controlledvice中的@exceptionHandler中处理什么特定异常

根据您的需要,我有一些类似的代码,请查看


@ControllerAdvice
public class ExceptionController {
@ExceptionHandler(value = PageNotFoundException.class)
public String pageNotFoundException(PageNotFoundException exception){
return "error/404";
}
@ExceptionHandler(value = AuthFailedException.class)
public String authFailedException(AuthFailedException exception){
return "error/401";
}
@ExceptionHandler(value = ServerException.class)
public String serverException(ServerException exception){
return "error/500";
}
}
Afterwards, you can throw any of the given type of exception.
please note, you have to create such your exception.
Example:

公共类PageNotFoundException扩展了RuntimeException{

}


I hope, it helps!

最新更新