一、單個(gè)controller范圍的異常處理

package com.xxx.secondboot.web;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;
import com.xxx.secondboot.exception.MyExceptionResponse;
import io.swagger.annotations.Api;
@Api("測(cè)試controllerAdvice和全局異常處理")
@RestController
@RequestMapping("/advice1")
public class AdviceController {
@RequestMapping(value = "/test1", method = RequestMethod.GET)
public String test1() {
throw new RuntimeException("advice1 - exception1");
}
@RequestMapping(value = "/test2", method = RequestMethod.GET)
public String test2() {
throw new RuntimeException("advice1 - exception2");
}
@ExceptionHandler(RuntimeException.class)
public MyExceptionResponse exceptionHandler() {
MyExceptionResponse resp = new MyExceptionResponse();
resp.setCode(300);
resp.setMsg("exception-Handler");
return resp;
}
}
分享標(biāo)題:springboot全局異常處理詳解-創(chuàng)新互聯(lián)
本文地址:http://chinadenli.net/article26/dsjejg.html
成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供用戶體驗(yàn)、商城網(wǎng)站、搜索引擎優(yōu)化、云服務(wù)器、做網(wǎng)站、手機(jī)網(wǎng)站建設(shè)
聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請(qǐng)盡快告知,我們將會(huì)在第一時(shí)間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如需處理請(qǐng)聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時(shí)需注明來源: 創(chuàng)新互聯(lián)
猜你還喜歡下面的內(nèi)容