spring自定义controller全局异常拦截

2020-12-13 06:24

阅读:427

标签:ast   fast   imp   pack   str   soft   ali   class   hat   

--异常类可以按需要自定义
package com.dhht.wechat.exception;


import com.alibaba.fastjson.JSONObject;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;

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

/**
* @Author: sh
* @Description: GlobalExceptionHandler 异常
* @Date: 22:12 2019/6/13
*/
@RestControllerAdvice
public class GlobalExceptionHandler {

@ExceptionHandler(value=Exception.class)
public Map exceptionHandler(Exception e){
e.printStackTrace();
Map resultMap = new HashMap();
resultMap.put("code",500);
resultMap.put("message","exception");
resultMap.put("data",null);
return resultMap;
}
}

spring自定义controller全局异常拦截

标签:ast   fast   imp   pack   str   soft   ali   class   hat   

原文地址:https://www.cnblogs.com/sung1024/p/11178396.html


评论


亲,登录后才可以留言!