title: How to save user by using form-data in spring boot rest & postman?
body: <p>I am developing a spring boot Rest API for login and registration. I was able to save the data in the database by using @RequestBody from the body of a postman as raw data. But I want to send form data from the postman with every field. In this case which annotation should I use in the controller.</p>
  
  <p>If anyone has a simple example, that would be great!</p>
  
  <p>Please check the image :</p>
  
  <p><a href="https://i.stack.imgur.com/nOwfr.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/nOwfr.png" alt="https://i.imgur.com/BWU63rK.png"></a></p>
  
  <p>Dao Class -</p>
  
  <pre><code>@Repository
  public class CustomerDaoImpl implements CustomerDao {
  
  @Autowired
  private SessionFactory sessionFactory;
  
  @Override
  public List&lt;Customer&gt; getCustomers() {
  
      Session session = sessionFactory.getCurrentSession(); 
  
      Query&lt;Customer&gt; query = session.createQuery("from Customer", 
                                                  Customer.class);
  
      List&lt;Customer&gt; customers = query.getResultList();
  
      return customers;
  }
  
  @Override
  public Customer getCustomer(int id) {
  
      Session session = sessionFactory.getCurrentSession(); 
  
      Customer customer = session.get(Customer.class, id);
  
      return customer;
  }
  
  @Override
  public void saveCustomer(Customer theCustomer) {
  
      Session session = sessionFactory.getCurrentSession();
  
      session.saveOrUpdate(theCustomer);
  
  }
  
  @Override
  public void deleteCustomer(int Id) {
  
      Session session = sessionFactory.getCurrentSession();
  
      Query query = session.createQuery("Delete from Customer where id=:customerId");
  
      query.setParameter("customerId", Id);
  
      query.executeUpdate();
  }
  
  @Override
  public Customer getCustomer(String emailId, String password) {
      Customer customer = null;
      Session session = sessionFactory.getCurrentSession();
      Query&lt;Customer&gt; query = session.createQuery("from Customer where emailId=:emailId and "
              + " password=:password");
  
      query.setParameter("emailId", emailId);
      query.setParameter("password", password);
  
      List&lt;Customer&gt; list = query.getResultList();
  
      try {
          return customer = list.get(0);
      }
      catch(Exception e) {
          e.getMessage();
          return null;
      }
   }
  
  }
  </code></pre>
  
  <p>POJO Class -</p>
  
  <pre><code>import java.sql.Timestamp;
  
  
  
  @Entity
  @Table(name="tbl_user_register")
  @JsonInclude(Include.NON_EMPTY) 
  @JsonIgnoreProperties(ignoreUnknown = true)
  
  public class Customer {
  
  @Id
  @Column(name="user_id")
  @GeneratedValue(strategy=GenerationType.IDENTITY)
  private int id;
  
  @Column(name="name")
  private String name;
  
  @Column(name="email_id")
  private String emailId;
  
  @Column(name="mobile")
  private String mobile;
  
  @Column(name="business_name")
  private String businessName;
  
  @Column(name="address")
  private String address;
  
  @Column(name="password")
  private String password;
  
  @Column(name="created")
  @CreationTimestamp
  private Timestamp created;
  
  @Column(name="user_type")
  private int userType;
  
  @Column(name="parent_type")
  private int parentType;
  
  public Customer() {
      super();
  }
  
  public Customer(String name, String emailId, String mobile, String businessName, String address, String password,
          Timestamp created, int userType, int parentType) {
      super();
      this.name = name;
      this.emailId = emailId;
      this.mobile = mobile;
      this.businessName = businessName;
      this.address = address;
      this.password = password;
      this.created = created;
      this.userType = userType;
      this.parentType = parentType;
  }
  
  
  
  public Customer(int id, String name, String emailId, String mobile, String businessName, String address,
          String password, Timestamp created, int userType, int parentType) {
      super();
      this.id = id;
      this.name = name;
      this.emailId = emailId;
      this.mobile = mobile;
      this.businessName = businessName;
      this.address = address;
      this.password = password;
      this.created = created;
      this.userType = userType;
      this.parentType = parentType;
  }
  
  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;
  }
  
  public String getEmailId() {
      return emailId;
  }
  
  public void setEmailId(String emailId) {
      this.emailId = emailId;
  }
  
  public String getMobile() {
      return mobile;
  }
  
  public void setMobile(String mobile) {
      this.mobile = mobile;
  }
  
  public String getBusinessName() {
      return businessName;
  }
  
  public void setBusinessName(String businessName) {
      this.businessName = businessName;
  }
  
  public String getAddress() {
      return address;
  }
  
  public void setAddress(String address) {
      this.address = address;
  }
  
  public String getPassword() {
      return password;
  }
  
  public void setPassword(String password) {
      this.password = password;
  }
  
  public Timestamp getCreated() {
      return created;
  }
  
  public void setCreated(Timestamp created) {
      this.created = created;
  }
  
  public int getUserType() {
      return userType;
  }
  
  public void setUserType(int userType) {
      this.userType = userType;
  }
  
  public int getParentType() {
      return parentType;
  }
  
  public void setParentType(int parentType) {
      this.parentType = parentType;
  }
  
  @Override
  public String toString() {
      return "Customer [id=" + id + ", name=" + name + ", emailId=" + emailId + ", mobile=" + mobile
              + ", businessName=" + businessName + ", address=" + address + ", password=" + password + ", created="
              + created + ", userType=" + userType + ", parentType=" + parentType + "]";
   }
  </code></pre>
  
  <p>}</p>
  
  <p>Controller - </p>
  
  <pre><code>@RestController
  @RequestMapping("/api")
  public class CustomerController {
  
  @Autowired
  CustomerService customerService;
  ResponseHandler response;   
  
  @GetMapping("/customers")
  public ResponseEntity&lt;List&lt;Customer&gt;&gt; getCustomers(){
  
      List&lt;Customer&gt; list = customerService.getCustomers();
      return new ResponseEntity&lt;List&lt;Customer&gt;&gt;(list, HttpStatus.OK);
  }
  
  
  @PostMapping(value="/login")
  public Customer getCustomer(@RequestParam(value="emailId") String emailId, @RequestParam(value="password") String password) {
  
  
      Customer theCustomer = customerService.getCustomer(emailId, password);
  
      if(theCustomer == null) {
          throw new CustomerNotFoundException("Customer not found - "+emailId);
      }
      return theCustomer;
  }
  
  
  
  @PostMapping(value = "/customers", consumes=MediaType.MULTIPART_FORM_DATA_VALUE)
  public Customer saveCustomer(@ModelAttribute Customer customer) {
  
      customerService.saveCustomer(customer);
      return customer;
      }
  
  }
  </code></pre>
  
  <p>This is what I getting - <a href="https://imgur.com/RnMkztk" rel="nofollow noreferrer">https://imgur.com/RnMkztk</a></p>