thymeleaf_form : single checkbox

This commit is contained in:
haerong22
2021-07-10 15:10:21 +09:00
parent 6755588d90
commit 7ed1e1dab1
8 changed files with 70 additions and 0 deletions

View File

@@ -0,0 +1,17 @@
package hello.itemservice.domain.item;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
@Data
@AllArgsConstructor
@NoArgsConstructor
@Builder
public class DeliveryCode {
private String code;
private String displayName;
}

View File

@@ -2,6 +2,8 @@ package hello.itemservice.domain.item;
import lombok.Data;
import java.util.List;
@Data
public class Item {
@@ -10,6 +12,11 @@ public class Item {
private Integer price;
private Integer quantity;
private Boolean open;
private List<String> regions;
private ItemType itemType;
private String deliveryCode;
public Item() {
}

View File

@@ -32,6 +32,10 @@ public class ItemRepository {
findItem.setItemName(updateParam.getItemName());
findItem.setPrice(updateParam.getPrice());
findItem.setQuantity(updateParam.getQuantity());
findItem.setOpen(updateParam.getOpen());
findItem.setRegions(updateParam.getRegions());
findItem.setItemType(updateParam.getItemType());
findItem.setDeliveryCode(updateParam.getDeliveryCode());
}
public void clearStore() {

View File

@@ -0,0 +1,13 @@
package hello.itemservice.domain.item;
public enum ItemType {
BOOK("도서"),
FOOD("음식"),
ETC("기타");
private final String description;
ItemType(String description) {
this.description = description;
}
}

View File

@@ -3,6 +3,7 @@ package hello.itemservice.web.form;
import hello.itemservice.domain.item.Item;
import hello.itemservice.domain.item.ItemRepository;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.*;
@@ -10,6 +11,7 @@ import org.springframework.web.servlet.mvc.support.RedirectAttributes;
import java.util.List;
@Slf4j
@Controller
@RequestMapping("/form/items")
@RequiredArgsConstructor
@@ -39,6 +41,7 @@ public class FormItemController {
@PostMapping("/add")
public String addItem(@ModelAttribute Item item, RedirectAttributes redirectAttributes) {
log.info("item.open = {}", item.getOpen());
Item savedItem = itemRepository.save(item);
redirectAttributes.addAttribute("itemId", savedItem.getId());
redirectAttributes.addAttribute("status", true);

View File

@@ -33,6 +33,14 @@
</div>
<hr class="my-4">
<!-- single checkbox -->
<div>판매 여부</div>
<div>
<div class="form-check">
<label for="open" class="form-check-label">판매 오픈</label>
<input type="checkbox" id="open" th:field="*{open}" class="form-check-input">
</div>
</div>
<div class="row">
<div class="col">

View File

@@ -38,6 +38,15 @@
<hr class="my-4">
<!-- single checkbox -->
<div>판매 여부</div>
<div>
<div class="form-check">
<label for="open" class="form-check-label">판매 오픈</label>
<input type="checkbox" id="open" th:field="${item.open}" class="form-check-input">
</div>
</div>
<div class="row">
<div class="col">
<button class="w-100 btn btn-primary btn-lg" type="submit">저장</button>

View File

@@ -40,6 +40,15 @@
<hr class="my-4">
<!-- single checkbox -->
<div>판매 여부</div>
<div>
<div class="form-check">
<label for="open" class="form-check-label">판매 오픈</label>
<input type="checkbox" id="open" th:field="${item.open}" class="form-check-input" disabled>
</div>
</div>
<div class="row">
<div class="col">
<button class="w-100 btn btn-primary btn-lg"