title: How form data are binding to the DTO class' private members by spring MVC
body: <p>I am developing a Spring MVC project where I am getting some data from UI form. I have a DTO class having private members in it. When I submit the form data then the FrontController(Dispatcher Servlet) invokes a method of Controller class because of <code>@RequestMapping</code> annotation. In this method, I am passing the reference of DTO class as an argument and printing the value of member variables of DTO class on the console by invoking getter methods.
  But I am not understanding how automatically the object of DTO class is creating and the form data are binding to the member variables of the DTO class. Please tell me how it is working?</p>
  
  <p>Controller class</p>
  
  <pre><code>package com.soni.web.controller;
  
  import org.springframework.stereotype.Component;
  import org.springframework.web.bind.annotation.RequestMapping;
  import org.springframework.web.bind.annotation.RequestMethod;
  import org.springframework.web.servlet.ModelAndView;
  import com.soni.web.dto.StudentRecordsDTO;
  
  @Component
  @RequestMapping("/")
  public class StudentRecords {
  
      public StudentRecords() {
  System.out.println(getClass().getName());
      }
  
      @RequestMapping(value="/signup", method = RequestMethod.POST)
      public String signup(StudentRecordsDTO studentRecordsDTO) {
  
      System.out.println(studentRecordsDTO.getId());
      System.out.println(studentRecordsDTO.getName());
  
      return "/registration_success.html";
     }
  
  }
  </code></pre>
  
  <p>DTO class</p>
  
  <pre><code>package com.soni.web.dto;
  
  public class StudentRecordsDTO {
  
      private int id;
      private String name;
  
      public StudentRecordsDTO(int id, String name) {
          this.id = id;
          this.name = name;
      }
  
      public int getId() {
          return id;
      }
  
      public void setId(int id) {
          this.id = id;
      }
  
      public String getName() {
          return name;
      }
  
      public void setName(String name) {
          this.name = name;
      }
  }
  </code></pre>
  
  <p>HTML Form</p>
  
  <pre><code>&lt;!DOCTYPE html&gt;
  &lt;html&gt;
  &lt;head&gt;
  &lt;meta charset="ISO-8859-1"&gt;
  &lt;title&gt;Insert title here&lt;/title&gt;
  &lt;/head&gt;
  &lt;body&gt;
  &lt;form action="signup" method ="post"&gt;
  &lt;input type  = "num" name="id"&gt;
  &lt;input type = "text" name="name"&gt;
  &lt;input type = "password" name="pwd"&gt;
  &lt;input type = "num" name = "nm"&gt;
  &lt;input type = "submit" value="press"&gt;
  &lt;/form&gt;
  &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>