2
2
.
.
4
4
.
.
4
4
@
@
R
R
e
e
q
q
u
u
e
e
s
s
t
t
P
P
a
a
r
r
a
a
m
m
I
I
n
n
f
f
o
o
[
[
G
G
]
]
@RequestParam Annotation
is used to read HTTP Request Parameters
is assigned to end-point Input Parameter - to Input Parameter of a @RequestMapping Method inside Controller
stores HTTP Request Parameter that has the same as that Input Parameter (into that Input Parameter)
MyController.java
@ResponseBody
@RequestMapping("/Hello")
public String sayHello(@RequestParam String name) {
return "Hello " + name;
}
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_httprequest_requestparam (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_httprequest_requestparam.controllers;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
@Controller
public class MyController {
@ResponseBody
@RequestMapping("/Hello")
public String hello(@RequestParam String name) {
return "Hello " + name;
}
}
hello()
MyController
http://localhost:8080/Hello?name=John
Browser
R
R
e
e
s
s
u
u
l
l
t
t
s
s
http://localhost:8080/Hello?name=John
Application Structure
pom.xml
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
</dependencies>