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;
    	}
    
    }
    

      

  • 相关阅读:
    Java1:Chapter3
    css3圆角和阴影效果
    css3兼容各版本浏览器前缀
    DOM
    数组方法
    Math方法
    JSON
    字符串方法
    日期对象
    定时器
  • 原文地址:https://www.cnblogs.com/haerwang/p/8078919.html
Copyright © 2011-2022 走看看