비슷하면서도 다른 DTO, VO, Entity의 차이에 대해서 알아보자.
@Getter
@Setter
public class MonitorDto {
private String name;
private Integer price;
private Integer count;
public MonitorDto(String name, Integer price, Integer count) {
this.name = name;
this.price = price;
this.count = count;
}
}
@Getter
public class Monitor {
private final String name;
private final Integer price;
private final Integer count;
public Monitor(String name, Integer price, Integer count) {
this.name = name;
this.price = price;
this.count = count;
}
public Integer getTotal() {
return price * count;
}
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
Monitor monitor = (Monitor) o;
return Objects.equals(name, monitor.name) && Objects.equals(price, monitor.price) && Objects.equals(count, monitor.count);
}
@Override
public int hashCode() {
return Objects.hash(name, price, count);
}
}
@Entity
public class Monitor {
@Id @GeneratedValue
private Long id;
@Column
private String name;
@Column
private Integer price;
@Column
private Integer count;
public Monitor() {
}
public Monitor(String name, Integer price, Integer count) {
this.name = name;
this.price = price;
this.count = count;
}
public Integer getTotal() {
return price * count;
}
}