码迷,mamicode.com
首页 > 编程语言 > 详细

springboot实现自定义的错误页面展示

时间:2019-04-19 09:14:13      阅读:178      评论:0      收藏:0      [点我收藏+]

标签:details   使用   log   pack   gis   intern   color   serve   net   

https://blog.csdn.net/trusause/article/details/84299886 参考

SpringBoot默认的错误处理机制
默认效果为: 返回一个默认的错误页面 Whitelabel Error Page
这里使用这个类:
package com.c23i23l.c123.config;

import org.springframework.boot.web.server.ErrorPage;
import org.springframework.boot.web.server.ErrorPageRegistrar;
import org.springframework.boot.web.server.ErrorPageRegistry;
import org.springframework.context.annotation.Configuration;
import org.springframework.http.HttpStatus;

@Configuration
public class ErrorConfigurar implements ErrorPageRegistrar {

    @Override
    public void registerErrorPages(ErrorPageRegistry registry) {
        ErrorPage[] errorPages = new ErrorPage[2];
        errorPages[0] = new ErrorPage(HttpStatus.NOT_FOUND, "/error404");
        errorPages[1] = new ErrorPage(HttpStatus.INTERNAL_SERVER_ERROR, "/500.html");

        registry.addErrorPages(errorPages);
    }
}

即完成了自定义的页面跳转,其实/error404和/error500是controller层的页面跳转.

springboot实现自定义的错误页面展示

标签:details   使用   log   pack   gis   intern   color   serve   net   

原文地址:https://www.cnblogs.com/ukzq/p/10733555.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!