1. 테이블 생성

package shop.mtcoding.blog.board;
import jakarta.persistence.*;
import lombok.Data;
import java.time.LocalDateTime;
@Table(name="board_tb")
@Data
@Entity // 테이블 생성하기 위해 필요한 어노테이션
public class Board { // User 1 -> Board N
@Id // PK 설정
@GeneratedValue(strategy = GenerationType.IDENTITY) // auto_increment 전략
private int id;
private String title;
private String content;
private int userId; // 테이블에 만들어 질때 user_id
private LocalDateTime createdAt;
}
2. 데이터 초기화
[ resource/db/data.sql ]
insert into user_tb(username, password, email, created_at) values('ssar', '1234', 'ssar@nate.com', now());
insert into user_tb(username, password, email, created_at) values('cos', '1234', 'cos@nate.com', now());
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());


classpath 설정 안 되어있으면 더미데이터 못찾아서 h2-console에 안 뜸
Share article