@RestController Annotation tells Spring that Class is Controller. (it contains Endpoints)
Endpoints in @RestController Class can only return data. (they can't return Views like HTML or Thymeleaf)
Using @RestController is the same as using @Controller in combination with @ResponseBody.
Application Schema [Results]
Spring Boot Starters
Create Project: springboot_controller_annotation_restcontroller (add Spring Boot Starters from the table)
Create Package: controllers (inside main package)
– Create Class: MyController.java (inside controllers package)
MyController.java
package com.ivoronline.springboot_controller_annotation_restcontroller.controllers;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
@RestController
public class MyController {
@RequestMapping("/Hello")
public String hello() {
return "Hello from Controller";
}
}