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

springboot 全局捕获异常

时间:2019-07-02 09:23:11      阅读:107      评论:0      收藏:0      [点我收藏+]

标签:代码   ret   hand   code   response   handle   运行时   body   bsp   

未被try catch的运行时异常都会被以下代码捕获

import org.springframework.web.bind.annotation.*;

import java.util.HashMap;
import java.util.Map;

@ControllerAdvice
public class EEcontroller {
    @ExceptionHandler(RuntimeException.class)
    @ResponseBody
    public Map<String,String> errorInfo(){
        Map<String,String> map=new HashMap<>();
        map.put("code","500");
        return  map;
    }
}

 

springboot 全局捕获异常

标签:代码   ret   hand   code   response   handle   运行时   body   bsp   

原文地址:https://www.cnblogs.com/hhxylm/p/11118408.html

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