@ResponseStatus 放在类上
@RequestMapping("/testResponseStatusException")public String testResponseStatusException(@RequestParam("i") Integer i){ if(i==13){ throw new UsernameNotmatchPasswordException();}System.out.println("testResponseStatusException");return "success";}@ResponseStatus(value=HttpStatus.FORBIDDEN, reason="账号和密码不匹配")public class UsernameNotmatchPasswordException extends RuntimeException{ private static final long serialVersionUID = 1L;}
@ResponseStatus 放在方法上
@ResponseStatus(value=HttpStatus.NOT_FOUND, reason="测试")@RequestMapping("/testResponseStatusException")public String testResponseStatusException(@RequestParam("i") Integer i){ if(i==13){ throw new UsernameNotmatchPasswordException(); } System.out.println("testResponseStatusException"); return "success";}