--异常类可以按需要自定义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 */@RestControllerAdvicepublic class GlobalExceptionHandler { @ExceptionHandler(value=Exception.class) public Map<String,Object> exceptionHandler(Exception e){ e.printStackTrace(); Map<String,Object> resultMap = new HashMap<>(); resultMap.put("code",500); resultMap.put("message","exception"); resultMap.put("data",null); return resultMap; }}
转载于:https://www.cnblogs.com/sung1024/p/11178396.html
转载请注明原文地址: https://win8.8miu.com/read-24987.html