-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
90 additions
and
3 deletions.
There are no files selected for viewing
17 changes: 17 additions & 0 deletions
17
jpashop2/src/main/java/jpabook/jpashop/controller/BookForm.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
package jpabook.jpashop.controller; | ||
|
||
import lombok.Getter; | ||
import lombok.Setter; | ||
|
||
@Getter @Setter | ||
public class BookForm { | ||
|
||
private Long id; | ||
|
||
private String name; | ||
private int price; | ||
private int stockQuantity; | ||
|
||
private String author; | ||
private String isbn; | ||
} |
2 changes: 1 addition & 1 deletion
2
...a/jpabook/jpashop/web/HomeController.java → ...ok/jpashop/controller/HomeController.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
36 changes: 36 additions & 0 deletions
36
jpashop2/src/main/java/jpabook/jpashop/controller/ItemController.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
package jpabook.jpashop.controller; | ||
|
||
import jpabook.jpashop.domain.item.Book; | ||
import jpabook.jpashop.service.ItemService; | ||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.stereotype.Controller; | ||
import org.springframework.ui.Model; | ||
import org.springframework.web.bind.annotation.GetMapping; | ||
import org.springframework.web.bind.annotation.PostMapping; | ||
|
||
@Controller | ||
@RequiredArgsConstructor | ||
public class ItemController { | ||
|
||
private final ItemService itemService; | ||
|
||
@GetMapping(value = "/items/new") | ||
public String createForm(Model model) { | ||
model.addAttribute("form", new BookForm()); | ||
return "items/createItemForm"; | ||
} | ||
|
||
@PostMapping(value = "/items/new") | ||
public String create(BookForm form) { | ||
Book book = new Book(); | ||
book.setName(form.getName()); | ||
book.setPrice(form.getPrice()); | ||
book.setStockQuantity(form.getStockQuantity()); | ||
book.setAuthor(form.getAuthor()); | ||
book.setIsbn(form.getIsbn()); | ||
|
||
itemService.saveItem(book); | ||
|
||
return "redirect:/items"; | ||
} | ||
} |
2 changes: 1 addition & 1 deletion
2
...jpabook/jpashop/web/MemberController.java → .../jpashop/controller/MemberController.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
.../java/jpabook/jpashop/web/MemberForm.java → ...pabook/jpashop/controller/MemberForm.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
package jpabook.jpashop.web; | ||
package jpabook.jpashop.controller; | ||
|
||
import lombok.Getter; | ||
import lombok.Setter; | ||
|
34 changes: 34 additions & 0 deletions
34
jpashop2/src/main/resources/templates/items/createItemForm.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
<!DOCTYPE HTML> | ||
<html xmlns:th="http://www.thymeleaf.org"> | ||
<head th:replace="fragments/header :: header" /> | ||
<body> | ||
<div class="container"> | ||
<div th:replace="fragments/bodyHeader :: bodyHeader"/> | ||
<form th:action="@{/items/new}" th:object="${form}" method="post"> | ||
<div class="form-group"> | ||
<label th:for="name">상품명</label> | ||
<input type="text" th:field="*{name}" class="form-control" placeholder="이름을 입력하세요"> | ||
</div> | ||
<div class="form-group"> | ||
<label th:for="price">가격</label> | ||
<input type="number" th:field="*{price}" class="form-control" placeholder="가격을 입력하세요"> | ||
</div> | ||
<div class="form-group"> | ||
<label th:for="stockQuantity">수량</label> | ||
<input type="number" th:field="*{stockQuantity}" class="form-control" placeholder="수량을 입력하세요"> | ||
</div> | ||
<div class="form-group"> | ||
<label th:for="author">저자</label> | ||
<input type="text" th:field="*{author}" class="form-control" placeholder="저자를 입력하세요"> | ||
</div> | ||
<div class="form-group"> | ||
<label th:for="isbn">ISBN</label> | ||
<input type="text" th:field="*{isbn}" class="form-control" placeholder="ISBN을 입력하세요"> | ||
</div> | ||
<button type="submit" class="btn btn-primary">Submit</button> | ||
</form> | ||
<br/> | ||
<div th:replace="fragments/footer :: footer" /> | ||
</div> <!-- /container --> | ||
</body> | ||
</html> |