页面不存在则跳转到404页面

This commit is contained in:
xiongxiaoyang
2020-12-24 16:45:48 +08:00
parent c9f1500976
commit 7494fe431a
3 changed files with 33 additions and 21 deletions

View File

@ -13,7 +13,7 @@ import org.springframework.web.bind.annotation.RestControllerAdvice;
*
* @author 11797*/
@Slf4j
@RestControllerAdvice
@RestControllerAdvice(basePackages = "com.java2nb.novel.controller")
public class CommonExceptionHandler {
/**

View File

@ -0,0 +1,26 @@
package com.java2nb.novel.core.advice;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
/**
* 页面异常处理器
*
* @author 11797
*/
@Slf4j
@ControllerAdvice(basePackages = "com.java2nb.novel.page")
public class PageExceptionHandler {
/**
* 处理所有异常
*/
@ExceptionHandler(Exception.class)
public String handlerException(Exception e) {
log.error(e.getMessage(), e);
//跳转页面过程中出现异常时统一跳转到404页面
return "404";
}
}