Notice
Recent Posts
Recent Comments
Link
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | 2 | 3 | 4 | 5 | 6 | |
7 | 8 | 9 | 10 | 11 | 12 | 13 |
14 | 15 | 16 | 17 | 18 | 19 | 20 |
21 | 22 | 23 | 24 | 25 | 26 | 27 |
28 | 29 | 30 | 31 |
Tags
- 파이썬
- CS지식
- 시큐리티
- Oracle
- 스프링
- 데이터
- JPA
- 자바스크립트
- CS
- Flutter
- 리눅스
- 자료구조
- Java
- 스프링부트
- spring
- baekjoon
- 플러터
- 자바
- 스프링 부트 쇼핑몰 프로젝트 with JPA
- 데이터베이스
- backjoon
- springboot
- python
- DB
- javascript
- 프로그래머스
- 네트워크
- postgresql
- 백준
- Spring Security
Archives
- Today
- Total
Jin's Dev Story
[스프링 부트 쇼핑몰 프로젝트 with JPA] 17-1. 게시판 - Entity 본문
Web & Android/스프링 부트 쇼핑몰 프로젝트 with JPA
[스프링 부트 쇼핑몰 프로젝트 with JPA] 17-1. 게시판 - Entity
woojin._. 2023. 10. 16. 20:12이 내용은 스프링 부트 쇼핑몰 프로젝트 with JPA 책을 학습한 내용입니다.
Entity
Board
@Entity @Getter @Setter @ToString @NoArgsConstructor @AllArgsConstructor @Table(name = "board") public class Board extends BaseTimeEntity { @Id @GeneratedValue(strategy = GenerationType.IDENTITY) @Column private Long id; // 게시판 번호 (자동 증가) @ManyToOne(fetch = FetchType.LAZY) @JoinColumn(name = "userId") // 외래키 설정 private UserEntity user; // 사용자 id // 시간 빼둠 @Column(length = 50) private String title; // 제목 @Column(length = 1000) private String content; // 내용 @Column(columnDefinition = "int default 0") private int recommend; // 좋아요 @JsonIgnore @BatchSize(size = 500) @OneToMany(mappedBy = "board", cascade = CascadeType.ALL, orphanRemoval = true) private List<Recommend> recommends; // 좋아요 리스트 @JsonIgnore @BatchSize(size = 500) @OneToMany(mappedBy = "board", cascade = CascadeType.ALL, orphanRemoval = true) private List<BoardComment> comments; // 댓글 리스트 public Board(UserEntity user, String title, String content) { this.user=user; this.title=title; this.content=content; } // 게시글 수정 public Board update(BoardUpdateDTO boardUpdateDTO) { this.title=boardUpdateDTO.getTitle(); this.content=boardUpdateDTO.getContent(); return this; } }
BoardComment
@Entity @Getter @Setter @ToString @NoArgsConstructor @AllArgsConstructor public class BoardComment extends BaseTimeEntity { @Id @GeneratedValue(strategy = GenerationType.IDENTITY) @Column private Long id; // 댓글 번호 (자동 증가) @ManyToOne(fetch = FetchType.LAZY) @JoinColumn(name = "boardId") // 외래키 설정 private Board board; // 게시판 번호 @ManyToOne(fetch = FetchType.LAZY) @JoinColumn(name = "parentId") private BoardComment parent; // 시간 빼둠 @ManyToOne(fetch = FetchType.LAZY) @JoinColumn(name = "userId") // 외래키 설정 private UserEntity user; // 사용자 id @Column(length = 500) private String content; // 내용 @Column(columnDefinition = "int default 0") private int recommend; // 댓글 좋아요 @JsonIgnore @BatchSize(size = 500) @OneToMany(mappedBy = "boardComment", cascade = CascadeType.ALL, orphanRemoval = true) private List<RecommendComment> recommendComments; // 좋아요 리스트 @OneToMany(mappedBy = "parent", orphanRemoval = true) private List<BoardComment> children = new ArrayList<>(); public BoardComment(UserEntity user, Board board, String content) { this.user=user; this.board=board; this.content=content; } public void updateParent(BoardComment parentComment) { this.parent=parentComment; } public BoardComment update(BoardCommentUpdateDTO boardCommentUpdateDTO) { this.content=boardCommentUpdateDTO.getContent(); return this; } }
Recomend
@Entity @Getter @Setter @ToString @IdClass(RecommendId.class) @NoArgsConstructor @AllArgsConstructor @Table(name = "recommend") public class Recommend { @Id @ManyToOne(fetch = FetchType.LAZY) @JoinColumn(name = "userId") private UserEntity user; @Id @ManyToOne(fetch = FetchType.LAZY) @JoinColumn(name = "boardId") private Board board; }
RecommendComment
import com.example.walkingmate_back.user.entity.UserEntity; import jakarta.persistence.*; import lombok.*; @Entity @Getter @Setter @ToString @IdClass(RecommendCommentId.class) @NoArgsConstructor @AllArgsConstructor @Table(name = "recommendComment") public class RecommendComment { @Id @ManyToOne(fetch = FetchType.LAZY) @JoinColumn(name = "userId") private UserEntity user; @Id @ManyToOne(fetch = FetchType.LAZY) @JoinColumn(name = "boardCommentId") private BoardComment boardComment; }
RecommendId
import com.example.walkingmate_back.user.entity.UserEntity; import lombok.AllArgsConstructor; import lombok.Data; import lombok.NoArgsConstructor; import java.io.Serializable; @Data @NoArgsConstructor @AllArgsConstructor public class RecommendId implements Serializable { private UserEntity user;
RecommendCommentId
import com.example.walkingmate_back.user.entity.UserEntity; import lombok.AllArgsConstructor; import lombok.Data; import lombok.NoArgsConstructor; import java.io.Serializable;
@Data
@NoArgsConstructor
@AllArgsConstructor
public class RecommendCommentId implements Serializable {
private UserEntity user;
private BoardComment boardComment;
}
```
'Web & Android > 스프링 부트 쇼핑몰 프로젝트 with JPA' 카테고리의 다른 글
[스프링 부트 쇼핑몰 프로젝트 with JPA] 17-3. 게시판 - Service (0) | 2023.10.16 |
---|---|
[스프링 부트 쇼핑몰 프로젝트 with JPA] 17-2. 게시판 - Controller (0) | 2023.10.16 |
[스프링 부트 쇼핑몰 프로젝트 with JPA] 16.장바구니 상품 삭제 & 주문 (0) | 2023.10.16 |
[스프링 부트 쇼핑몰 프로젝트 with JPA] 15. 장바구니 조회 (1) | 2023.10.16 |
[스프링 부트 쇼핑몰 프로젝트 with JPA] 14. 장바구니 담기 (0) | 2023.10.16 |