SpringBoot异常处理


/**
 * 全局的的异常拦截器
 *
 * @author cody
 */
@Slf4j
@RestControllerAdvice
public class GlobalExceptionHandler {

    /**
     * IllegalArgumentException
     *
     * @param e the e
     * @return the wrapper
     */
    @ExceptionHandler(IllegalArgumentException.class)
    @ResponseStatus(HttpStatus.OK)
    @ResponseBody
    public Wrapper illegalArgumentException(IllegalArgumentException e) {
        log.error("IllegalArgumentException={}", e.getMessage(), e);
        return WrapMapper.error("param error");
    }

    /**
     * IllegalStateException
     *
     * @param e the e
     * @return the wrapper
     */
    @ExceptionHandler(IllegalStateException.class)
    @ResponseStatus(HttpStatus.OK)
    @ResponseBody
    public Wrapper IllegalStateException(IllegalStateException e) {
        log.error("IllegalStateException={}", e.getMessage(), e);
        return WrapMapper.error();
    }

    /**
     * HttpMessageNotWritableException
     *
     * @param e the e
     * @return the wrapper
     */
    @ExceptionHandler(HttpMessageNotWritableException.class)
    @ResponseStatus(HttpStatus.OK)
    @ResponseBody
    public Wrapper HttpMessageNotWritableException(HttpMessageNotWritableException e) {
        log.error("HttpMessageNotWritableException={}", e.getMessage(), e);
        return WrapMapper.error();
    }


    /**
     * HttpMessageNotReadableException
     *
     * @param e the e
     * @return the wrapper
     */
    @ExceptionHandler(HttpMessageNotReadableException.class)
    @ResponseStatus(HttpStatus.OK)
    @ResponseBody
    public Wrapper HttpMessageNotReadableException(HttpMessageNotReadableException e) {
        log.error("HttpMessageNotReadableException={}", e.getMessage(), e);
        return WrapMapper.error();
    }
}
  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
项目详细功能参考项目演示内容即可项目优势:1、项目从零开始到完结 附带视频,源码以及相关辅助资料,适合学习使用,项目也可拿来即用。2、几乎全手写代码,功能流程详细 跟着可以独立完成,附带详细代码相关常见bug 和 调试解决方案,让大家学会跟踪快速解决问题。3、系统后端使用LayUI技术,对页面不精通的小伙伴也可以快速完成精美页面的设计及应用,支持统一后台管理,也可拿来做其他项目通用后台4、针对layui 相关技术点薄弱的学员提供相关技术点学习,让快速上手完成项目研发5、选材来自生活,项目真实感强,可用学习使用和就业面试使用,适合作为面试中提高实际项目经验...6、该项目前后端分离,满足前沿技术点..项目技术栈:- 数据库:MySQL8.0- 后端技术:SpringBoot,MyBatisPlus,JWT 等- 日志技术:Log4j- 数据库连接池:druid- 前端技术:LayUI, axios,Echarts,Ztree 等- Web容器:Apache Tomcat 9- 项目管理工具:Maven3.6- 思维导图设计工具:XMIND 8- 开发工具: IDEA2020, WebStorm2020- 数据库设计软件:Power Designer16.5特别提示:1、涉及相关技术点学习,更多侧重大学生或无项目经验以及项目经验较少的学员入门到项目完结项目实战2、项目中功能处理大多提供多种解决方式,如跨域访问,更多让大家了解解决方式的同时学会技术点应用3、加入bug的调试以及代码跟踪处理,更好的让学员更多学会如何解决问题
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值