代码结构
配置pom文件
<?xml version="1.0" encoding="UTF-8"?><project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://.zz.exception.UserNotExistException;import org.springframework.web.bind.annotation.GetMapping;import org.springframework.web.bind.annotation.PathVariable;import org.springframework.web.bind.annotation.RequestMapping;import org.springframework.web.bind.annotation.RestController;@RestController@RequestMapping("user")public class UserController { @GetMapping("/{id:\\d+}") public void get(@PathVariable String id) { throw new UserNotExistException(id); } @GetMapping("error2") public void get2() { int a=1/0; }}#运行结果
代码地址 github: 添加链接描述
以上所述是小编给大家介绍的SpringBoot统一异常处理详解整合,希望对大家有所帮助,如果大家有任何疑问请给我留言,小编会及时回复大家的。在此也非常感谢大家对网站的支持!