2
2
.
.
4
4
.
.
5
5
@
@
P
P
a
a
t
t
h
h
V
V
a
a
r
r
i
i
a
a
b
b
l
l
e
e
I
I
n
n
f
f
o
o
[
[
G
G
]
]
@PathVariable stores Path Component into Endpoint's Input Parameter.
Application Schema [Results]
Spring Boot Starters
GROUP
DEPENDENCY
DESCRIPTION
Web
Spring Web
Enables @Controller and @RequestMapping. Includes Tomcat Server.
P
P
r
r
o
o
c
c
e
e
d
d
u
u
r
r
e
e
Create Project: springboot_endpoint_annotation_pathvariable (add Spring Boot Starters from the table)
Create Package: controllers (inside main package)
– Create Class: MyController.java (inside package controllers)
MyController.java
package com.ivoronline.springboot_endpoint_annotation_pathvariable.controllers;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.ResponseBody;
@Controller
public class MyController {
@ResponseBody
@GetMapping("/Hello/{FirstName}/{age}")
public String hello(
@PathVariable("FirstName") String name, //IF NAMES ARE DIFFERENT
@PathVariable String age //IF NAMES ARE THE SAME
) {
return name + " is " + age + " years old";
}
}
hello()
MyController
http://localhost:8080/Hello/John/20
Browser
R
R
e
e
s
s
u
u
l
l
t
t
s
s
http://localhost:8080/Hello/John/20
Application Structure
pom.xml
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
</dependencies>