공부공부

spring 게시판 만들기 6.DTO

냘로하 2020. 8. 16. 13:45

DTO는 VO라고도 불리워진다고 한다.

일단 DTO를 만들자!

DTO를 만들때 참고해야 할 것 :

이 내용이 필수적으로 필요하다.

SPRING에서 저 컬럼들을 가져와서 매치시켜야 하기 때문에, DTO에서는 해당 컬럼들을 인식할수 있도록 만들어주면 된다.

Board2DTO 패키지와 클래스 생성!
DTO의 골격 완성

이렇게 dto의 골격을 완성시켰으면, getter와 setter를 만들고 DTO의 내용을 확인할수 있도록 tostring 작업을 진행하자.

package com.board2.DTO;

import java.util.Date;

public class Board2DTO {
	private String title, content;
	private int hit,boardno;
	private Date boarddate;
	public String getTitle() {
		return title;
	}
	public void setTitle(String title) {
		this.title = title;
	}
	public String getContent() {
		return content;
	}
	public void setContent(String content) {
		this.content = content;
	}
	public int getHit() {
		return hit;
	}
	public void setHit(int hit) {
		this.hit = hit;
	}
	public int getBoardno() {
		return boardno;
	}
	public void setBoardno(int boardno) {
		this.boardno = boardno;
	}
	public Date getBoarddate() {
		return boarddate;
	}
	public void setBoarddate(Date boarddate) {
		this.boarddate = boarddate;
	}
	@Override
	public String toString() {
		return "Board2DTO [title=" + title + ", content=" + content + ", hit=" + hit + ", boardno=" + boardno
				+ ", boarddate=" + boarddate + "]";
	}
}

 getter와 setter, toStirng 작업을 끝낸 이후, DAO나 컨트롤러에서 시작해서 쭈-욱 진행하면 된다. 다음글에서.