-
쇼핑몰프로젝트 --엔티티 만들기 (api기반)쇼핑몰 프로젝트 2024. 6. 15. 12:50
프로젝트 시작날짜 6/3
프로젝트 인원 4명
내가 맡은 부분 상품,카테고리,아이템리뷰
item클래스
package ypjs.project.domain; import jakarta.persistence.*; import lombok.Getter; import lombok.Setter; import java.time.LocalDateTime; import java.util.ArrayList; import java.util.List; @Entity @Getter @Setter public class Item { @Id @GeneratedValue @Column(name = "ITEM_ID") private Long itemId; @ManyToOne(fetch = FetchType.LAZY) @JoinColumn(name = "CATEGORY_ID") private Category category; @OneToMany(mappedBy = "item", cascade = CascadeType.ALL) private List<ItemReview> itemReviews = new ArrayList<>(); @Column(name = "ITEM_NAME") private String itemName; @Lob @Column(name = "ITEM_CONTENT", columnDefinition = "LONGTEXT") private String itemContent; @Column(name = "ITEM_PRICE") private int itemPrice; @Column(name = "ITEM_STOCK") private int itemStock; @Column(name = "ITEM_FILENAME") private String itemFilename; @Column(name = "ITEM_FILEPATH") private String itemFilepath; @Column(name = "ITEM_CREATEDATE") private LocalDateTime itemCreateDate; @Column(name = "ITEM_CNT") private int itemCnt; @Column(name = "ITEM_RATINGS") private double itemRatings; @Column(name = "LIKE_CONT") private int likeCont; //생성자 (dto만들 때 필요) public Item() {} public Item(Category category, String itemName, String itemContent, int itemPrice, int itemStock) { this.category = category; this.itemName = itemName; this.itemContent = itemContent; this.itemPrice = itemPrice; this.itemStock = itemStock; } //연관관계 메서드 public void setCategory(Category category) { this.category = category; } public void addItemReview(ItemReview itemReview) { itemReviews.add(itemReview); itemReview.setItem(this); } public void removeItemReview(ItemReview itemReview) { itemReviews.remove(itemReview); } }
category클래스
package ypjs.project.domain; import jakarta.persistence.*; import lombok.Getter; import ypjs.project.service.CategoryService; import java.util.ArrayList; import java.util.List; @Entity @Getter public class Category { @Id @GeneratedValue @Column(name = "CATEGORY_ID") private Long categoryId; //연관관계 메서드 @OneToMany(mappedBy = "category", cascade = CascadeType.ALL) private List<Item> items = new ArrayList<>(); //자신을 부모타입으로 가짐 @ManyToOne(fetch = FetchType.LAZY) @JoinColumn(name = "CATEGORY_PARENT_ID") private Category categoryParent; @Column(name = "CATEGORY_NAME") private String categoryName; //자식은 여러개 가질 수 있음 @OneToMany(mappedBy = "categoryParent") private List<Category> categoryChild = new ArrayList<>(); //생성자 public Category() {} public Category (Category categoryParent, String categoryName) { this.categoryParent = categoryParent; this.categoryName = categoryName; } //연관관계 메서드 public void addChildCategory(Category child) { this.categoryChild.add(child); child.categoryParent = this; } public void addItem(Item item) { items.add(item); item.setCategory(this); } /* private void setCategoryParentId(Category category) { category.CategoryParentId = this; } */ }
itemReview클래스
package ypjs.project.domain; import jakarta.persistence.*; import lombok.Getter; @Entity @Getter public class ItemReview { @Id @GeneratedValue @Column(name = "ITEM_REVIEW_ID") private Long itemReviewId; @ManyToOne @JoinColumn(name = "ITEM_ID") private Item item; @ManyToOne @JoinColumn(name = "MEMBER_ID") private Member member; @Column(name = "ITEM_SCORE") private int itemScore; @Column(name = "ITEM_REVIEW_NAME") private String itemReviewName; @Column(name = "ITEM_REVIEW_CONTENT") private String itemReviewContent; //생성자 (dto만들 때 필요) public ItemReview() {} public ItemReview(Item item,Member member, int itemScore, String itemReviewName, String itemReviewContent) { this.item = item; this.member = member; this.itemScore = itemScore; this.itemReviewName = itemReviewName; this.itemReviewContent = itemReviewContent; } //연관관계 메서드 public void setItem(Item item) { this.item = item; } }
'쇼핑몰 프로젝트' 카테고리의 다른 글
쇼핑몰 프로젝트 --아이템 등록, 수정 (화면구현) (0) 2024.06.17 쇼핑몰 프로젝트 --아이템 리뷰 등록, 조회, 수정, 삭제(api) (0) 2024.06.15 쇼핑몰프로젝트 --카테고리 당 아이템 조회(api기반) (0) 2024.06.15 쇼핑몰프로젝트 --아이템, 카테고리 수정, 삭제 (api기반) (0) 2024.06.15 쇼핑몰프로젝트 --상품, 카테고리 등록, 조회 (api기반) (0) 2024.06.15