@RequestMapping tells Spring for which URL to call the Endpoint.
Endpoint will be called for all types of HTTP Requests: GET, POST, UPDATE, DELETE.
To specify that Endpoint should be called only for specific types of HTTP Requests you can combine Annotations:
@GetMapping, @PostMapping.
Application Schema [Results]
Spring Boot Starters
Enables: @Controller, @ResponseBody, @RequestMapping, Tomcat Server
Create Project: controller_returns_text (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.controller_returns_text.controllers;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.ResponseBody;
@Controller
public class MyController {
@ResponseBody
@RequestMapping("/Hello")
public String hello() {
return "Hello from Controller";
}
}