Define the DTO

Follow the steps to define a DTO.

Context

You want to display the following information of a product:

  • Code

  • Name

  • Description

  • Picture

  • Price (currency and value)

Procedure

  1. Create a class with name org.training.data.ProductData.

    It is a POJO with these instance variables:

    private String code;
    private String name;
    private String description;
    private String pictureUrl;
    private PriceData price;
  2. Create getters and setters for those instance variables accordingly, such as:
    public void setCode(String code)
    {
       this.code = code;
    }
       
    public String getCode()
    {
       return code;
    }
  3. Create a separate class org.training.data.PriceData for the price, with these instance variables:
    private String currency;
    private double value;
  4. Create getters and setters again.