The request body refers to the data that the client sent in the body of the HTTP request. This data provides additional information to the server or sends the data that needs to be processed by the server. In a Spring Boot application, we use the @RequestBody annotation to map this request data to the Entity class object. These HTTP request data can be of primitive, non-primitive or object types. In this tutorial, we will learn how we can pass date in Postman request body.
Steps to pass date in Postman request body
We can easily understand the above concept using a Spring Boot application. In order to learn how to build a Spring Boot application, please refer to CRUD Operations with Spring Boot and MonogDB.
Step 1- Create an Entity class
We have created a Payment class that has a date field that we will pass through the postman request body.
import java.util.Date;
import jakarta.persistence.Entity;
import jakarta.persistence.GeneratedValue;
import jakarta.persistence.GenerationType;
import jakarta.persistence.Id;
import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;
@Getter
@Setter
@AllArgsConstructor
@NoArgsConstructor
@Entity(name = "tbl_payment")
public class Payment {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private int paymentId;
private double paymentAmt;
private String paymentMode;
private Date paymentDate;
}
Step 2- Create a Controller
After this, we create a PaymentController class where we do not perform any business logic operations; instead, we simply return the complete request that we receive from the client (postman request body: HTTP request).
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.paulsofts.employeeservice.model.Payment;
@RestController
@RequestMapping("/api/payment")
public class PaymentContoller {
@PostMapping("/get")
public Payment getPaymentDetails(@RequestBody Payment payment) {
return payment;
}
}
Step 3- Send date in Postman body
We pass the date filed in Postman as following: