Spring Controllers
Build Spring controllers using Java and Spring annotations
StartKey Concepts
Review core concepts you need to learn to master this subject
Mapping HTTP Requests
Base Path Mapping
Common Request Types
Accessing Parameters in Methods
REST Controllers
Response Exceptions
HttpStatus Type
Spring Specifying HTTP Status Code
Mapping HTTP Requests
Mapping HTTP Requests
@RequestMapping("/sayhello")
public String sayHello() {
return "Hello, world";
}
The @RequestMapping
annotation can be used at the method level or the class level to map an HTTP request to the appropriate controller method.
Responding to Requests with Spring
Lesson 1 of 1
- 1The Spring framework is an incredible resource to help us quickly build RESTful applications. The core functionality of these applications lies in their ability to receive requests, route them acco…
- 2The term REST stands for REpresentational State Transfer, and it describes the architectural technique used to facilitate communication between different systems via the web. Stateless requests are…
- 3We’ve discussed how to use @RequestMapping at the method level, now let’s discover how it can be used at the class level. When the @RequestMapping data annotation is used at the class level, the …
- 4In the Mapping Requests exercise, we discussed several parameters for the @RequestMapping data annotation. One of the arguments mentioned was the method argument. As a reminder, the method argument…
- 5In the previous exercise, we discussed the use of helper methods to specify the HTTP method being used. GET requests are used to retrieve information from the server, while POST, PUT, or DELETE req…
- 6In the previous exercise, we discussed the use of @RequestParam to pass data from query parameters to a method. @RequestParam is perfect to use when we want to filter the results or return several …
- 7So far we have seen how methods accept HTTP requests and how they pass data from those requests to method parameters. However, occasionally, the requests received will need to be more complex. For …
- 8Anytime an HTTP response is transmitted, a status code is included in the response. HTTP status codes are used to determine if the request was successful or if some type of error occurred and ever…
- 9We know HTTP status codes can be used to determine if a request was successfully processed or if an error was generated. However, we may want to fine-tune the HTTP response to give the user more in…
- 10In the previous exercise, we discussed the use of @ResponseStatus to apply custom HTTP status codes and reasons to an HTTP response. However, if an error is encountered, we can use ResponseStatusEx…
What you'll create
Portfolio projects that showcase your new skills
How you'll master it
Stress-test your knowledge with quizzes that help commit syntax to memory