标签:ControllerAdvice注解,ExceptionHandler注解
发布时间:2024-04-14
@RestController@b@public class HelloController {@b@ @b@@b@ @GetMapping("/hello2")@b@ public String hello2() {@b@ if(true){@b@ throw new RuntimeException();@b@ }@b@ return "Hello Spring Boot!";@b@ }@b@@b@}
import org.springframework.http.HttpStatus;@b@import org.springframework.web.bind.annotation.*;@b@@b@@b@@ControllerAdvice @b@public class GlobalExceptionHandler {@b@@b@@b@ @ExceptionHandler(Exception.class)@b@ @ResponseBody@b@ public String handleException(Exception e){@b@ return "1111";@b@ }@b@}