728x90
th:object, th:field 중요!!
Controller
Model에 Item 객체 추가
@GetMapping("/add")
public String addForm(Model model) {
model.addAttribute("item", new Item());
return "form/addForm";
}
Item 객체
import lombok.Data;
@Data
public class Item {
private Long id;
private String itemName;
private Integer price;
private Integer quantity;
public Item() {
}
public Item(String itemName, Integer price, Integer quantity) {
this.itemName = itemName;
this.price = price;
this.quantity = quantity;
}
}
Model 에서 추가해준 Item 객체의 값을 불러 올 수 있다.
*{itemName} 사용하면 html id, name, input 값 3가지를 불러올수 있다.
#id, name 안적어줘도 상관없음.
${item.itemName} , *{itemName} 둘다 같다.
HTML

728x90
'백엔드 > 타임리프' 카테고리의 다른 글
타임리프 라디오 버튼 (0) | 2021.09.15 |
---|---|
타임리프 체크박스 (0) | 2021.09.15 |
템플릿 (0) | 2021.09.13 |
타임리프 자바스크립트, JS each (0) | 2021.09.12 |
타임리프 block (0) | 2021.09.12 |