



기능적인 부분만 맡았습니다.
CREATE DATABASE spring;
use spring;
CREATE TABLE recipe_Board ( -- 레시피 보드
board_No INT AUTO_INCREMENT PRIMARY KEY,
food_name VARCHAR(200) NOT NULL,
board_title VARCHAR(200) NOT NULL,
board_content VARCHAR(2000) NOT NULL,
food_genre VARCHAR(100) NOT NULL,
board_view INT DEFAULT 0,
reg_date TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
thumbnail VARCHAR(200),
food_time INT DEFAULT 0,
numberEaters int DEFAULT 0,
Apoint INT DEFAULT 0,
member_id VARCHAR(200) NOT NULL
);
CREATE TABLE material ( -- 재료 리스트 테이블
material_id INT AUTO_INCREMENT PRIMARY KEY,
board_No INT,
material_name VARCHAR(200) NOT NULL,-- 재료이름
mensuration VARCHAR(200) NOT NULL,-- 재료량
type_Material VARCHAR(200) DEFAULT '소스',-- 요리재료의 종류
FOREIGN KEY (board_No) REFERENCES recipe_Board(board_No)
);
CREATE TABLE cooking ( -- 레이피 리스트 테이블
cooking_id INT AUTO_INCREMENT PRIMARY KEY,
board_No INT,
cook_title VARCHAR(200) NOT NULL, -- 레시피제복
cook_Method VARCHAR(2000) NOT NULL,-- 레시피내용
recommended VARCHAR(2000),-- 주의사항
cook_file VARCHAR(500) ,
FOREIGN KEY (board_No) REFERENCES recipe_Board(board_No)
);
CREATE TABLE cook_material ( -- 요리에 재료테이블
cooking_id INT,
material_id INT,
board_No INT,
FOREIGN KEY (board_No) REFERENCES recipe_Board(board_No),
FOREIGN KEY (board_No) REFERENCES material(material_id),
FOREIGN KEY (board_No) REFERENCES cooking(cooking_id)
);
기존 레시피 보드에
재료리스트, 요리과정, 요리과정에 필요한 재료(재료리스트에서추출예정)
가 필요해서 테이블을 4개 만들게 되었습니다.
요리과정에 필요한 재료(재료리스트에서추출예정) 가 왜 필요하나 싶을수도 있는데 제가 하려고하는것은 그 조리과정에서 들어가게될 필요한 재료를 나타내고 자 함입니다.
예를들어 재료리스트에 닭 100g , 고추장 1스푼 , 설탕 1스푼이 있다고 할때
요리과정 1.닭삶기 // 이에대한 필요재료 닭 100g 이런식으로 하고싶어
서 넣게 되었습니다.
@Getter
@Setter
@Builder
@NoArgsConstructor
@AllArgsConstructor
public class RecipeBoard {
private int boardNo; //게시판 고유값
private String foodName; // 음식이름
private String boardTitle; // 레시피 제목
private String boardContent; // 레시피 간단한 소개
private String foodGenre;// 음식 장르 (한중일양기)
private int boardView; //게시판 조회수
private Timestamp regDate; // 올린날짜
private String thumbnail; // 섭내일 파일
private int foodTime; //조리시간
private int numberEaters; // 인원수
private int apoint; // 평점
private String memberId; // 아이디
private List<Cooking> cookingList; // 조리과정리스트
private List<Material> materialList;// 요리 재료리스트
}
package com.springbootstudy.app.domain;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;
@Getter
@Setter
@Builder
@NoArgsConstructor
@AllArgsConstructor
public class Material {
// 확인 - test!
private int materialId;
private int boardNo; // ManyToOne 관계가 있던 RecipeBoard 대신 boardNo 필드를 사용합니다.
private String materialName; // 재료 이름
private String mensuration; // 재료 량
private String typeMaterial; // 재료종류( 재료, 조미료
}
@Getter
@Setter
@Builder
@NoArgsConstructor
@AllArgsConstructor
public class Cooking {
private int cookingId;
private int boardNo; // ManyToOne 관계가 있던 RecipeBoard 대신 boardNo 필드를 사용합니다.
private String cookTitle;
private String cookMethod;
private String recommended;
private String cookFile;
private List<CookMaterial> cookMaterial;
// Getter, Setter, toString 등 필요한 메서드 추가
}
@Getter
@Setter
@NoArgsConstructor
@AllArgsConstructor
public class CookMaterial {
private int materialId;
private int cookingId;
private int boardNo; // ManyToOne 관계가 있던 RecipeBoard 대신 boardNo 필드를 사용합니다.
private String materialName; //재료 이름
private String mensuration; //재료 양
// Getter, Setter, toString 등 필요한 메서드 추가
}
모두 boardNo 의 포린키로 묶여있다.
@Getter
@Setter
@Builder
@NoArgsConstructor
@AllArgsConstructor
public class Comment {
int commentId;
int boardNo;
String commentContent;
int commentPoint;
Timestamp createdAt;
String memberId;
}
댓글을 이용해 별점을 만들 계획
먼저 가장 기본인 board의 리스트를 뽑아보자
src/main/resources/mappers
원하는 xml 메퍼만들기 (RecipeMapper.xml)
Springboot에서는 JPA도 지원해서 기본적인건 자동으로 쿼리문을 만들어주는게 있는데 아직 배우지않은 것이기도 했고 포린키로 묶다보니까 결국에 원하는 데이터값을 뽑아내려면 내가직접 쿼리문 작성해야 됐기때문에 mybatis를 사용하기로 했었다.
레시피 보드
<mapper namespace="com.springbootstudy.app.mapper.RecipeMapper">
<!--레시피 리스트-->
<select id="recipeBoardList">
select * from Recipe_Board order by board_No desc
</select>
</mapper>