[Spring Boot] 6. Spring Boot Project (Store v1) in Curser_2.Controller

김미숙's avatar
Mar 27, 2025
[Spring Boot] 6. Spring Boot Project (Store v1) in Curser_2.Controller

LogController

package com.metacoding.storev1.log; import org.springframework.stereotype.Controller; import org.springframework.web.bind.annotation.GetMapping; @Controller public class LogController { @GetMapping("/log") public String list() { return "log/list"; } }
 

StoreController

package com.metacoding.storev1.store; import org.springframework.stereotype.Controller; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.PathVariable; import org.springframework.web.bind.annotation.PostMapping; @Controller // IoC (제어의역전) -> HashSet public class StoreController { @GetMapping("/") public String list() { return "store/list"; } @GetMapping("/store/save-form") public String saveForm() { return "store/save-form"; } @GetMapping("/store/{id}") public String detail(@PathVariable("id") int id) { return "store/detail"; } @GetMapping("/store/{id}/update-form") public String updateForm(@PathVariable("id") int id) { return "store/update-form"; } @PostMapping("/store/{id}/delete") public String delete(@PathVariable("id") int id) { return "redirect:/"; } @PostMapping("/store/save") public String save() { return "redirect:/"; } @PostMapping("/store/{id}/update") public String update(@PathVariable("id") int id) { return "redirect:/store/1"; } }
 

▪ 상품목록 page

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

▪ 상세보기 page

{{>layout/header}} <section> <a href="/store/1/update-form">수정화면가기</a> <form action="/store/1/delete" method="post"> <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>
localhost:8080/store/1
notion image
 

▪ 수정 page

{{>layout/header}} <section> <form action="/store/1/update" method="post" > <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>
localhost:8080/store/1/update-form
상품수정 을 누르면 redirection 되서 상품목록 page로 이동된다
notion image
 

▪ 상품등록 page

{{>layout/header}} <section> <form action="/store/save" method="post"> <input type="text" placeholder="상품명"><br> <input type="text" placeholder="수량"><br> <input type="text" placeholder="가격"><br> <button type="submit">상품등록</button> </form> </section> </body> </html>
➡ localhost:8080/store/save-form
상품등록 을 누르면 redirection 되서 상품목록 page로 이동된다
notion image

▪ 구매목록 page

{{>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>
➡ localhost:8080/log
notion image
Share article

parangdajavous