본문 바로가기
☕Java/Spring

[20210716] Spring + MyBatis를 이용한 로그인 및 게시판 2 - DTO

by 캔 2021. 7. 16.

이번 프로젝트에서는 데이터베이스의 테이블이 두 개이므로 DTO도 두 개 만든다. 아래는 boardc 테이블의 데이터를 전송하기 위한 BoardDTO, customer 테이블의 데이터를 전송하기 위한 CustomerDTO이다.

DTO의 구조를 간단히 설명하면, 테이블의 데이터 칼럼(열)에 해당하는 변수들이 private으로 선언되어 있고 매개변수가 없는 생성자와 변수들을 매개변수로 하는 생성자들이 선언되어 있다. 또한, 변수를 외부에서 호출 또는 수정할 수 있는 getter와 setter 메서드도 선언되어 있다.

//BoardDTO.java

package customer.dto;

import java.sql.Timestamp;

public class BoardDTO {

	private int b_no;
	private int b_user;
	private String b_ownernick;
	private String b_title;
	private String b_content;
	private Timestamp b_date;
	
	public BoardDTO() {
		super();
	}

	public BoardDTO(int b_no, int b_user, String b_ownernick, String b_title, String b_content, Timestamp b_date) {
		super();
		this.b_no = b_no;
		this.b_user = b_user;
		this.b_ownernick = b_ownernick;
		this.b_title = b_title;
		this.b_content = b_content;
		this.b_date = b_date;
	}

	public int getB_no() {
		return b_no;
	}

	public void setB_no(int b_no) {
		this.b_no = b_no;
	}

	public int getB_user() {
		return b_user;
	}

	public void setB_user(int b_user) {
		this.b_user = b_user;
	}

	public String getB_ownernick() {
		return b_ownernick;
	}

	public void setB_ownernick(String b_ownernick) {
		this.b_ownernick = b_ownernick;
	}

	public String getB_title() {
		return b_title;
	}

	public void setB_title(String b_title) {
		this.b_title = b_title;
	}

	public String getB_content() {
		return b_content;
	}

	public void setB_content(String b_content) {
		this.b_content = b_content;
	}

	public Timestamp getB_date() {
		return b_date;
	}

	public void setB_date(Timestamp b_date) {
		this.b_date = b_date;
	}
}
//CustomerDTO.java

package customer.dto;

public class CustomerDTO {
	
	private int c_no;
	private String c_id;
	private String c_pw;
	
	public CustomerDTO() {
		super();
	}

	public CustomerDTO(int c_no, String c_id, String c_pw) {
		super();
		this.c_no = c_no;
		this.c_id = c_id;
		this.c_pw = c_pw;
	}

	public int getC_no() {
		return c_no;
	}

	public void setC_no(int c_no) {
		this.c_no = c_no;
	}

	public String getC_id() {
		return c_id;
	}

	public void setC_id(String c_id) {
		this.c_id = c_id;
	}

	public String getC_pw() {
		return c_pw;
	}

	public void setC_pw(String c_pw) {
		this.c_pw = c_pw;
	}
}