Posts

Showing posts with the label @RestController

Spring @RestController Annotation Example

Image
In this section we will learn about  @RestController  Annotation.   The  @RestController   annotation is mainly utilized for building restful web services utilizing Spring MVC. It is a convenience annotation, this annotation itself annotated with @ResponseBody and @Controller annotation. The class annotated with @RestController annotation returns JSON replication in all the methods. @RestController public class UserController { @GetMapping ( "/users" ) public User getUser ( ) { //TODO } } The following example creates a Spring Boot web application which uses @RestController .  Project Directory Pom.xml <? xml version ="1.0" encoding ="UTF-8" ?> < project xmlns ="http://maven.apache.org/POM/4.0.0" xmlns: xsi ="http://www.w3.org/2001/XMLSchema-instance" xsi :schemaLocation ="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd" > < modelVersion &g