2
2
.
.
3
3
.
.
2
2
@
@
R
R
e
e
s
s
t
t
C
C
o
o
n
n
t
t
r
r
o
o
l
l
l
l
e
e
r
r
I
I
n
n
f
f
o
o
[
[
G
G
]
]
[
[
R
R
]
]
@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
GROUP
DEPENDENCY
DESCRIPTION
Web
Spring Web
Enables: @RestController, @RequestMapping, Tomcat Server
P
P
r
r
o
o
c
c
e
e
d
d
u
u
r
r
e
e
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";
}
}
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>