- Updated source code for the article "Returning Custom Status Codes from Spring MVC Controllers" to be included in the spring-rest project

This commit is contained in:
amedviediev
2016-01-30 23:05:06 +02:00
parent 21e3d74963
commit 453d995385
6 changed files with 2 additions and 70 deletions

View File

@@ -0,0 +1,24 @@
package org.baeldung.web.controller.status;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
@Controller
public class ExampleController {
@RequestMapping(value = "/controller", method = RequestMethod.GET)
@ResponseBody
public ResponseEntity sendViaResponseEntity() {
return new ResponseEntity(HttpStatus.NOT_ACCEPTABLE);
}
@RequestMapping(value = "/exception", method = RequestMethod.GET)
@ResponseBody
public ResponseEntity sendViaException() {
throw new ForbiddenException();
}
}

View File

@@ -0,0 +1,9 @@
package org.baeldung.web.controller.status;
import org.springframework.http.HttpStatus;
import org.springframework.web.bind.annotation.ResponseStatus;
@ResponseStatus(value = HttpStatus.FORBIDDEN, reason="To show an example of a custom message")
public class ForbiddenException extends RuntimeException {
}