Java:自定义异常处理类

版权声明:本博客为记录本人学习过程而开,内容大多从网上学习与整理所得,若侵权请告知! https://blog.csdn.net/Fly_as_tadpole/article/details/84670268

注意几个注解:@ControllerAdvice     @ExceptionHandler    @ResponseBody

package com.sayhello.sayhello.Handle;


import com.sayhello.sayhello.Exception.GirlException;
import com.sayhello.sayhello.Utils.ResultUtils;
import com.sayhello.sayhello.domain.Result;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;

@ControllerAdvice
public class GirlHandle {

    @ExceptionHandler(value = GirlException.class)
    @ResponseBody
    public Result handleException(GirlException e){
        //System.out.println(e.getMessage());
        return ResultUtils.error(e.getCode(),e.getMessage());
    }
}

猜你喜欢

转载自blog.csdn.net/Fly_as_tadpole/article/details/84670268