0
0
Spring Bootframework~30 mins

@RequestParam for query strings in Spring Boot - Mini Project: Build & Apply

Choose your learning style9 modes available
Using @RequestParam for Query Strings in Spring Boot
📖 Scenario: You are building a simple Spring Boot web application that greets users based on their name passed in the URL query string.
🎯 Goal: Create a Spring Boot controller that reads a name parameter from the query string using @RequestParam and returns a greeting message.
📋 What You'll Learn
Create a Spring Boot controller class named GreetingController
Add a method greet that handles GET requests at /greet
Use @RequestParam to get the name query parameter
Return a greeting message including the name value
Set a default value for name as Guest if not provided
💡 Why This Matters
🌍 Real World
Web applications often need to read user input from URL query strings to customize responses, such as search filters or user greetings.
💼 Career
Understanding @RequestParam is essential for backend developers working with Spring Boot to handle HTTP requests and build REST APIs.
Progress0 / 4 steps
1
Create the GreetingController class
Create a public class called GreetingController annotated with @RestController.
Spring Boot
Need a hint?

Use @RestController to make the class a REST controller.

2
Add the greet method with @GetMapping
Inside GreetingController, add a public method called greet that returns a String. Annotate it with @GetMapping("/greet").
Spring Boot
Need a hint?

Use @GetMapping("/greet") to map GET requests to the method.

3
Add @RequestParam to get the name query parameter
Modify the greet method to accept a String parameter called name annotated with @RequestParam(name = "name", defaultValue = "Guest").
Spring Boot
Need a hint?

Use @RequestParam to read the query string parameter name with a default value.

4
Return a greeting message including the name
In the greet method, return a String that says "Hello, " followed by the name parameter.
Spring Boot
Need a hint?

Use string concatenation to create the greeting message.