一、单个controller范围的异常处理package com.xxx.secondboot.WEB;import org.springframework.web.bind.annotation.ExceptionHandler;impo
一、单个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("测试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; }}
--结束END--
本文标题: springboot全局异常处理详解
本文链接: https://lsjlt.com/news/226439.html(转载时请注明来源链接)
有问题或投稿请发送至: 邮箱/279061341@qq.com QQ/279061341
2024-05-24
2024-05-24
2024-05-24
2024-05-24
2024-05-24
2024-05-24
2024-05-24
2024-05-24
2024-05-24
2024-05-24
回答
回答
回答
回答
回答
回答
回答
回答
回答
回答
0