Java:自定义异常处理类
生活随笔
收集整理的這篇文章主要介紹了
Java:自定义异常处理类
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
注意幾個注解:@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());} }?
總結
以上是生活随笔為你收集整理的Java:自定义异常处理类的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: Java:异常处理的一些注意事项
- 下一篇: java美元兑换,(Java实现) 美元