标签:tps map code == nal name 测试 user return
作用在类和方法上面 更改返回的代码和错误消息
类上 通过throw new UserName***Exception()抛出
@ResponseStatus(value=HttpStatus.FORBIDDEN, reason="用户名和密码不匹配!") public class UserNameNotMatchPasswordException extends RuntimeException{ /** * */ private static final long serialVersionUID = 1L; }
方法上 方法执行通过,但是返回会有错误,因为配置了@ResponseStatus
@ResponseStatus(reason="测试",value=HttpStatus.NOT_FOUND) @RequestMapping("/testResponseStatusExceptionResolver") public String testResponseStatusExceptionResolver(@RequestParam("i") int i){ if(i == 13){ throw new UserNameNotMatchPasswordException(); } System.out.println("testResponseStatusExceptionResolver..."); return "success"; }
Spring MVC 异常处理 - ResponseStatusExceptionResolver
标签:tps map code == nal name 测试 user return
原文地址:https://www.cnblogs.com/eason-d/p/9256115.html