For api application development using Spring Boot and Hibernate on Java 8, need to store the bean object values(For Example bookId, bookName, bookDescription) into db. Please find the Sample classes
BeanObject.java
package com.example;
public class BeanObject {
private String bookId;
private String bookName;
private String bookDescription;
/**
* @return the bookId
*/
public String getBookId() {
return bookId;
}
/**
* @param bookId the bookId to set
*/
public void setBookId(String bookId) {
this.bookId = bookId;
}
/**
* @return the bookName
*/
public String getBookName() {
return bookName;
}
/**
* @param bookName the bookName to set
*/
public void setBookName(String bookName) {
this.bookName = bookName;
}
/**
* @return the bookDescription
*/
public String getBookDescription() {
return bookDescription;
}
/**
* @param bookDescription the bookDescription to set
*/
public void setBookDescription(String bookDescription) {
this.bookDescription = bookDescription;
}
}
DomainObject.java
/**
*
*/
package com.example;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.Table;
/**
* @author pandiaraj
*
*/
@Entity
@Table(name = "BOOKS")
public class DomainObject {
private String bookId;
private String bookName;
private String bookDescription;
/**
* @return the bookId
*/
@ID
@Column(name = "ID", unique = true, nullable = false, length = 100)
public String getBookId() {
return bookId;
}
/**
* @param bookId the bookId to set
*/
public void setBookId(String bookId) {
this.bookId = bookId;
}
/**
* @return the bookName
*/
@Column(name = "NAME", length = 30)
public String getBookName() {
return bookName;
}
/**
* @param bookName the bookName to set
*/
public void setBookName(String bookName) {
this.bookName = bookName;
}
/**
* @return the bookDescription
*/
@Column(name = "DESCRIPTION", length = 30)
public String getBookDescription() {
return bookDescription;
}
/**
* @param bookDescription the bookDescription to set
*/
public void setBookDescription(String bookDescription) {
this.bookDescription = bookDescription;
}
}
Which is simple and best way to mapping the request object values to hibernate dao object(domain model), a indentation is fastest way to execute line of code it means reduce the api response time. We followed below ways
- Using getter and setter methods.
- Using Apache Commons - BeanUtils.copyProperties(toBean, fromBean);
Is there any other ways to mapping the objects!