SpringBoot自定义错误页面面

2022-10-27 16:21:12 浏览数 (1)

实现ErrorController接口

代码语言:javascript复制
package com.jmy.controller;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.boot.web.servlet.error.ErrorController;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

@Controller
@RequestMapping("/error")
public class BaseErrorPage implements ErrorController {

    Logger logger = LoggerFactory.getLogger(BaseErrorPage.class);

    @Override
    public String getErrorPath() {
        logger.info("进入自定义错误页面");
        return "other/404";
    }

    @RequestMapping
    public String error() {
        return getErrorPath();
    }
}

0 人点赞