Java:自定义异常处理类
生活随笔
收集整理的這篇文章主要介紹了
Java:自定义异常处理类
小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.
注意幾個(gè)注解:@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)@ResponseBodypublic Result handleException(GirlException e){//System.out.println(e.getMessage());return ResultUtils.error(e.getCode(),e.getMessage());} }?
總結(jié)
以上是生活随笔為你收集整理的Java:自定义异常处理类的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: Java:异常处理的一些注意事项
- 下一篇: springboot java.util