zoukankan      html  css  js  c++  java
  • 3-全局异常处理

    新建一个切面即可:

    package com.haerwang.springboot.exceptionHandler;
    
    import java.util.HashMap;
    import java.util.Map;
    
    import org.springframework.web.bind.annotation.ControllerAdvice;
    import org.springframework.web.bind.annotation.ExceptionHandler;
    import org.springframework.web.bind.annotation.ResponseBody;
    
    /**
     * @author haerwang
     * @ControllerAdvice 标识这个类是切面
     */
    @ControllerAdvice
    public class GlobalExceptionHandler {
    
    	@ExceptionHandler(RuntimeException.class)
    	@ResponseBody//拦截后返回给前端的是json格式
    	public Map<String, Object> exceptionHandler(RuntimeException e) {
    		Map<String, Object> reslut = new HashMap<String, Object>();
    		reslut.put("code", 500);
    		return reslut;
    	}
    
    }
    

      

  • 相关阅读:
    2017.10.17笔记
    鼠标移入移出方向判断
    12.14 css3
    百叶窗 蒙版 图层
    banner轮播
    12.13
    12.11 jq基础
    11.30 AJAX
    11.28 Window事件 iframe操作
    11.28.cookie
  • 原文地址:https://www.cnblogs.com/haerwang/p/8078919.html
Copyright © 2011-2022 走看看