외부 교육/빅데이터 엔지니어 교육

DAO DTO Vo 정리 - 1

민둥곰 2021. 12. 1. 18:01

DTO (Data Trasnfer Object)

Data 를 따로 저장 처리 등 Data 모음 이라고 볼 수 있다.

Data 처리 로직만 존재할 뿐(getter, setter) 비즈니스 로직과 같은 코드는 담지 아니한다.

Data 의 컨테이너라는 의미

다른 시스템에 전달할때 쓰는 용도

 

DTO 예제:

public class DTOExamp {
  private String name;
  private int value;
  private String data;

  public String getName() {
    return this.name;
  }
  public int getValue() {
    return this.value;
  }
  public getData() {
    return this.data;
  }

  public void setName(String name) {
    this.name = name;
  }
  public void setValue(int value) {
    this.value = value;
  }
  public void setData(String data) {
    this.data = data;
  }
}

 

DAO (Data Access Object)

DB, Web 과 같은 접속에 관한 내용만 따로 빼놓은 것을 의미한다

public class DTOExamp {
  public void mydbConnection(DTOExamp dto) {

    String MyJdbcDriver = "com.mysql.cj.jdbc.Driver";
    String MyJdbcUrl = "jdbc:mysql://localhost/DBName";
    String dbUser = "user";
    String dbPassword = "password@!";

    Class.forName(MyJdbcDriver);

    Connection c = DriverManager.getConnection(MyJdbcUrl,dbUser, dbPassword);

    PreparedStatement ps = c.prepareStatement("Insert into users(name,value,data) value(?,?,?");
    ps.setString(1, dto.getName());
    ps.setInt(2, dto.getValue());
    ps.setString(3, dto.getData());

    ps.executeUpdate();

    ps.close();
    c.close();
  }
}

 

 

 

VO(Value Object)

DTO 와 유사하지만 값이 변하지 않으며, 값으로만 비교되는 특징이 존재

데이터 그 자체로 의미 있는 것을 담고 있는 객체(Obejct)

Read-Only 

VOExamp v1 = new VoExamp();
VOExamp v2 = new VoExamp();

System.out.println(v1 == v2); // true

class VOExamp {
  private String name;
  private int value;
  private String data;

  public String getName() {
    return this.name;
  }
  public int getValue() {
    return this.value;
  }
  public String getData() {
    return this.data;
  }

  public void setName(String name) {
    this.name = name;
  }
  public void setValue(int value) {
    this.value = value;
  }
  public void setData(String data) {
    this.data = data;
  }
  public final static VoExamp MDG = new VOExamp("민둥곰","0","EX Data");
  public final static VoExamp MDY = new VOExamp("민둥양","1","EX Data");
}
// 위 내용은 의미만 담은 예제이며 실제 사용 예제는 아래

class Color {
  private int r;
  private int g;
  private int b;

  public String getR() {
    return this.r;
  }
  public int getG() {
    return this.g;
  }
  public String getB() {
    return this.b;
  }

  public void setR(int r) {
    this.r = r;
  }
  public void setG(int G) {
    this.g = g;
  }
  public void setB(int B) {
    this.b = b;
  }
  public final static Color RED = new Color(255,0,0);
  public final static Color GREEN = new Color(0,128,0);
}

 

Ref: https://ijbgo.tistory.com/9

 

VO vs DTO

VO vs DTO VO(Value Object) -       데이터 그 자체로 의미 있는 것을 담고 있는 객체이다. -       DTO와 동일한 개념이나 차이점은 Read–Only 속성 객체이다. -       간단한 독립체( Entit..

ijbgo.tistory.com

https://m.blog.naver.com/jihoon8912/220240747123

'외부 교육 > 빅데이터 엔지니어 교육' 카테고리의 다른 글

DTO 상세 정리  (0) 2021.12.01