[스프링부트] 16. 상점 v1 그림 그리기

백하림's avatar
Mar 20, 2025
[스프링부트] 16. 상점 v1 그림 그리기
notion image

Controller 코드

package com.metacoding.storev1; import org.springframework.stereotype.Controller; import org.springframework.web.bind.annotation.GetMapping; @Controller public class HelloController { @GetMapping("/log/list") public String t1() { return "log/list"; } @GetMapping("/store/list") public String t2() { return "store/list"; } @GetMapping("/store/detail") public String t3() { return "store/detail"; } @GetMapping("/store/save-form") public String t4() { return "store/save-form"; } @GetMapping("/store/update-form") public String t5() { return "store/update-form"; } }

header 코드

<!doctype html> <html lang="en"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1"> <title>blog</title> </head> <body> <nav> <ul> <li> <a href="#">상품목록</a> </li> <li> <a href="#">상품등록</a> </li> <li> <a href="#">구매목록</a> </li> </ul> </nav> <hr>

log/list 코드

{{>layout/header}} <section> <table border="1"> <tr> <th>주문번호</th> <th>상품명(조인)</th> <th>구매개수</th> <th>총가격</th> <th>구매자이름</th> </tr> <tr> <td>1</td> <td>바나나</td> <td>5개</td> <td>15000원</td> <td>ssar</td> </tr> <tr> <td>2</td> <td>바나나</td> <td>5개</td> <td>15000원</td> <td>ssar</td> </tr> <tr> <td>3</td> <td>딸기</td> <td>5개</td> <td>10000원</td> <td>cos</td> </tr> </table> </section> </body> </html>
notion image

store/detail 코드 (상세보기)

{{> layout/header}} <section> <a href="#">수정화면가기</a> <form action="#"> <button type="submit">삭제</button> </form> <div> 번호 : 1 <br> 상품명 : 바나나 <br> 상품가격 : 3000원 <br> 상품재고 : 100개 <br> </div> <form action="#"> <input type="hidden" value="1"> <input type="text" placeholder="당신은 누구인가요?"> <input type="text" placeholder="Enter 개수"> <button type="submit">구매</button> </form> </section> </body> </html>
notion image

store/list 코드

{{>layout/header}} <section> <table border="1"> <tr> <th>번호</th> <th>상품명</th> <th></th> </tr> <tr> <td>1</td> <td>바나나</td> <td><a href="#">상세보기</a></td> </tr> <tr> <td>2</td> <td>딸기</td> <td><a href="#">상세보기</a></td> </tr> </table> </section> </body> </html>
notion image

store/save-form 코드

{{> layout/header}} <section> <form action="#"> <input type="text" placeholder="상품명"><br> <input type="text" placeholder="수량"><br> <input type="text" placeholder="가격"><br> <button type="submit">상품등록</button> </form> </section> </body> </html>
notion image

store/update-form 코드

{{> layout/header}} <section> <form action="#"> <input type="text" value="바나나"><br> <input type="text" value="100"><br> <input type="text" value="3000"><br> <button type="submit">상품수정</button> </form> </section> </body> </html>
notion image

💡
alt + shitf + o 하면 import를 한 번에 할 수 있다 !

Store 코드

package com.metacoding.storev1.store; import jakarta.persistence.Entity; import jakarta.persistence.GeneratedValue; import jakarta.persistence.GenerationType; import jakarta.persistence.Id; import jakarta.persistence.Table; import lombok.Getter; import lombok.NoArgsConstructor; @Getter @NoArgsConstructor // JPA가 ObjectMapping을 위해 new할 때 사용함. 무조건 붙여라 @Table(name = "store_tb") @Entity // 설정파일에서 테이블을 생성 해준다. public class Store { @Id @GeneratedValue(strategy = GenerationType.IDENTITY) private Integer id; private String name; private Integer stock; // 재고 private Integer price; }

Log 코드

package com.metacoding.storev1.log; import jakarta.persistence.Entity; import jakarta.persistence.GeneratedValue; import jakarta.persistence.GenerationType; import jakarta.persistence.Id; import jakarta.persistence.Table; import lombok.Getter; import lombok.NoArgsConstructor; @Getter @NoArgsConstructor // JPA가 ObjectMapping을 위해 new할 때 사용함. 무조건 붙여라 @Table(name = "log_tb") @Entity // 설정파일에서 테이블을 생성 해준다. public class Log { @Id @GeneratedValue(strategy = GenerationType.IDENTITY) private Integer id; private Integer storeId; // 상품 ID (FK) private Integer qty; // 구매 수량 private Integer totalPrice; // 총 구매 금액 qty * store(price) private String buyer; // 구매자 }
notion image
notion image
Share article

harimmon