springboot 定制错误页面

本文介绍了项目中常见的HTTP状态码,如400 BadRequest、401 Unauthorized、403 Forbidden等,并解释了它们的区别。同时,还提供了在Spring Boot项目中如何自定义错误页面的方法。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

项目中经常遇到的异常情况

  • 400-Bad Request
  • 401-Unauthorized

    If the request already included Authorization credentials, then the 401 response indicates that authorization has been refused for those credentials.

  • 403-Forbidden

    The server understood the request, but is refusing to fulfill it.

  • 404-Resource not found
  • 500-Internal Server Error

    定制错误页面的方法

  1. 在src/main/resource/templates/error/目录中增加
  2. 在src/main/resource/public/error/目录中增加

其中第一种方式的优先级大于第二种。
springboot-error-handling

参考文档

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值