博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
Spring Boot笔记-404错误统一管理
阅读量:1950 次
发布时间:2019-04-27

本文共 921 字,大约阅读时间需要 3 分钟。

这里有一点要注意:

spring boot错误的页面都会到error的请求中,所以可以用如下的方式统一管理

package com.xxxxx.apc.controller;import com.apc.apc.utils.ResultUtil;import org.springframework.web.bind.annotation.RequestMapping;import org.springframework.web.bind.annotation.RestController;import javax.servlet.http.HttpServletRequest;import java.util.HashMap;import java.util.Map;@RestControllerpublic class ErrorController implements org.springframework.boot.autoconfigure.web.ErrorController {    @Override    public String getErrorPath() {        return "error";    }    @RequestMapping("/error")    public Object handleError(HttpServletRequest request){        Integer statusCode = (Integer) request.getAttribute("javax.servlet.error.status_code");        if(statusCode == 404){            Map
map = new HashMap<>(); map.put("tip", "can not find page"); return ResultUtil.error(map); } return null; }}

运行截图如下:

转载地址:http://vdmif.baihongyu.com/

你可能感兴趣的文章
vi光标移动及定位
查看>>
修改或隐藏Nginx的版本号
查看>>
linux中文本编辑vi命令插入技巧
查看>>
linux中vi中的剪切和删除
查看>>
linux中的vi命令文本查找
查看>>
vim搜索设置高亮和取消高亮
查看>>
linux配置vi
查看>>
vimdiff比较两个文件
查看>>
linux安装tftp服务器
查看>>
windows下mysql的安装
查看>>
【Batch】批处理读取文本内容并分割字符串
查看>>
【Yaml】了解yaml文件格式
查看>>
超级详细从零搭建在线博客,基于 sphinx + markdown + nginx + docker 架构 ! 附源码
查看>>
【git】使用ssh密钥访问Github
查看>>
python读取excel
查看>>
PDFBox学习总结
查看>>
TestNG入门程序
查看>>
zabbix configure: error: Invalid Net-SNMP directory - unable to find net-snmp-config
查看>>
yum源配置
查看>>
tar命令解压文件后造成目录权限更改
查看>>