使用的模板引擎为Freemarker,页面存放位置如图
application文件中配置映射文件位置
spring.freemarker.template-loader-path=classpath:/templates/
编写一个类实现ErrorController来处理异常页面
import org.springframework.boot.web.servlet.error.ErrorController;
import org.springframework.web.bind.annotation.RequestMapping;
import javax.servlet.http.HttpServletRequest;
public class ErrorHandleController implements ErrorController {
@Override
public String getErrorPath() {
return "/error";
}
@RequestMapping("/error")
public String handleErroe(HttpServletRequest request) {
//获取statusCode
Integer statusCode = (Integer) request.getAttribute("javax.servlet.error.status_code");
if (statusCode == 401) {
return "/401";
} else if (statusCode &#