
1. 게시판 테이블 생성하기
package shop.mtcoding.blog.board;
import lombok.Data;
import org.hibernate.annotations.CreationTimestamp;
import javax.persistence.*;
import java.time.LocalDateTime;
@Data
@Entity // 붙여야 테이블이 만들어지고 조회된게 해당객체로 파싱됨
@Table(name = "board_tb")
public class Board {
@Id //primary key
@GeneratedValue(strategy = GenerationType.IDENTITY)// auto
private int id;
private String title;
private String content; // 데이터가 여러건이라 테이블로 쪼개야함
private int userId; //카멜을 쓰면 언더스코어로 만들어줌 -> 외래키
@CreationTimestamp
private LocalDateTime createdAt;
}

2. 더미 데이터 입력하기
- db.sqld 파일에 게시글 추가하는 쿼리 작성하기
insert into board_tb(title, content, user_id, created_at) values('제목1','내용1', 1, now());
insert into board_tb(title, content, user_id, created_at) values('제목2','내용2', 1, now());
insert into board_tb(title, content, user_id, created_at) values('제목3','내용3', 1, now());
insert into board_tb(title, content, user_id, created_at) values('제목4','내용4', 2, now());

Share article