mirror of
https://gitee.com/likeadmin/likeadmin_java.git
synced 2026-06-25 14:37:40 +08:00
优化404拦截写法
This commit is contained in:
@@ -13,6 +13,7 @@ import org.springframework.web.HttpRequestMethodNotSupportedException;
|
||||
import org.springframework.web.bind.MethodArgumentNotValidException;
|
||||
import org.springframework.web.bind.MissingServletRequestParameterException;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
import org.springframework.web.servlet.NoHandlerFoundException;
|
||||
|
||||
import java.util.Objects;
|
||||
|
||||
@@ -38,6 +39,16 @@ public class GlobalException {
|
||||
return AjaxResult.failed(HttpEnum.SYSTEM_ERROR.getCode(), e.getMessage());
|
||||
}
|
||||
|
||||
/**
|
||||
* 拦截404异常
|
||||
*/
|
||||
@ResponseStatus(HttpStatus.OK)
|
||||
@ExceptionHandler(NoHandlerFoundException.class)
|
||||
@ResponseBody
|
||||
public AjaxResult<Object> handleNoHandlerFoundException(NoHandlerFoundException e){
|
||||
return AjaxResult.failed(HttpEnum.REQUEST_404_ERROR.getCode(), e.getMessage());
|
||||
}
|
||||
|
||||
/**
|
||||
* 拦截自定义抛出异常
|
||||
*/
|
||||
|
||||
Reference in New Issue
Block a user