Javatpoint Logo
Javatpoint Logo

Spring Annotations

Here, we will discuss about the annotations that we have used in our project.

Note - The @RestController and @RequestMapping annotations are Spring MVC annotations. They are not specific to Spring Boot.

The @RestController and @RequestMapping annotations

The @RestController is a stereotype annotation. It adds @Controller and @ResponseBody annotations to the class. We need to import org.springframework.web.bind.annotation package in our file, in order to implement it.

In our controller class. It can be used like:

The @RestController annotation informs to the Spring to render the result back to the caller.

The @RequestMapping annotation is used to provide routing information. It tells to the Spring that any HTTP request should map to the corresponding method. We need to import org.springframework.web.annotation package in our file.

As in the following example, we have a method hello() which should map with /hello url.

You can also specify request method in @RequestMapping annotation as we have done in the following example.

A GET request by localhost:8080/hello url will map to the hello() method.

Next TopicSpring Boot DM

Help Others, Please Share

facebook twitter google plus pinterest

Learn Latest Tutorials


Trending Technologies

B.Tech / MCA