thymeleaf_form : single checkbox
This commit is contained in:
@@ -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;
|
||||
|
||||
}
|
||||
@@ -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() {
|
||||
}
|
||||
|
||||
|
||||
@@ -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() {
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
@@ -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);
|
||||
|
||||
@@ -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">
|
||||
|
||||
@@ -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>
|
||||
|
||||
@@ -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"
|
||||
|
||||
Reference in New Issue
Block a user