1、搭建一个SpringBoot项目并在pom.xml中添加web启动即可<dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-web</artifactId></dependency>
2、编写自定义异常类UserRuntimeException
3、新建一个异常处理器ControllerExceptionHandler
4、Controller层写一个简单的UserController
5、启动项目,开始测试
6、先测试一个会抛出自定义异常的例子在浏览器器输入http://localhost/user/12345
7、再测试一个正常的例子在浏览器器输入http://localhost/user/123456