- 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:
@@ -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();
|
||||
}
|
||||
}
|
||||
@@ -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 {
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user