2
2
.
.
1
1
0
0
.
.
1
1
@
@
R
R
e
e
s
s
p
p
o
o
n
n
s
s
e
e
B
B
o
o
d
d
y
y
I
I
n
n
f
f
o
o
[
[
G
G
]
]
@ResponseBody defines that Endpoint returns Data. (this tutorial is identical to "Return - Text")
This means that we are not feeding return value into some Template. (like HTML, JSP, Thymeleaf)
Instead return value should be returned directly through HTTP Response. (Text or Object Serialized as JSON)
If Endpoint returns an Object it gets Deserialized. (It is returned as JSON)
Application Schema [Results]
Spring Boot Starters
GROUP
DEPENDENCY
DESCRIPTION
Web
Spring Web
Enables: @RequestMapping, Tomcat Server
P
P
r
r
o
o
c
c
e
e
d
d
u
u
r
r
e
e
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";
}
}
hello()
MyController
http://localhost:8080/Hello
Browser
R
R
e
e
s
s
u
u
l
l
t
t
s
s
http://localhost:8080/Hello
Application Structure
pom.xml
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
</dependencies>