0
0
Spring Bootframework~15 mins

Request DTO for input in Spring Boot - Mini Project: Build & Apply

Choose your learning style9 modes available
Create a Request DTO for Input in Spring Boot
📖 Scenario: You are building a simple Spring Boot application that accepts user data through a web form. To handle this data safely and clearly, you need to create a Request DTO (Data Transfer Object) that will hold the input values.
🎯 Goal: Build a Request DTO class in Spring Boot with fields for name (String) and age (int). This class will be used to receive input data from a client.
📋 What You'll Learn
Create a Java class named UserRequest in the dto package.
Add private fields name (String) and age (int).
Generate public getter and setter methods for both fields.
Add a no-argument constructor and an all-argument constructor.
Use standard Java naming conventions.
💡 Why This Matters
🌍 Real World
Request DTOs are used in web applications to safely receive and validate user input data from forms or API calls.
💼 Career
Understanding how to create and use DTOs is essential for backend developers working with Spring Boot or similar frameworks to build clean and maintainable APIs.
Progress0 / 4 steps
1
Create the UserRequest class with package declaration
Create a Java class named UserRequest inside the dto package. Add the package declaration package dto; at the top.
Spring Boot
Need a hint?

Start by declaring the package and the class skeleton.

2
Add private fields name and age
Inside the UserRequest class, add two private fields: a String name and an int age.
Spring Boot
Need a hint?

Use private String name; and private int age; inside the class.

3
Add constructors: no-argument and all-argument
Add a public no-argument constructor and a public constructor with parameters String name and int age that sets the fields.
Spring Boot
Need a hint?

Write two constructors: one empty and one that sets both fields.

4
Add public getter and setter methods for name and age
Add public getter and setter methods for the name and age fields in the UserRequest class.
Spring Boot
Need a hint?

Write getter and setter methods for both fields following Java naming rules.