Front 관련 기술
thymeleaf 폼 관련 처리
끄적끄적
2022. 7. 16. 10:42
input박스 구현 : 폼 구현시 th:value를 써도 되고, 수정등 화면에서는 th:filed 활용가능
아래와 같이 form action에 th:object 정의후 th:field 사용하면 id, name, value 등 자동으로 설정해줌
<form action="/strategy" th:action th:object="${strategyInfo}" method="post">
<table>
<tbody>
<tr>
<td width="200"> measuringScreenAreaX : </td><td width="500">
<input type="text" class="form-control" th:field="*{measuringScreenAreaX}"></td>
</tr>
해당 Controller마다 반복적으로 필드값을 model에 넣어야 할 경우 : 아래처럼 @ModelAttribue로 구현하면 regions, itemTypes가 항상 내려간다. 체크박스나 라이오박스 구현시 th:each 등으로 사용
@ModelAttribute("regions")
public Map<String, String> regions() {
Map<String, String> regions = new LinkedHashMap<>();
regions.put("SEOUL", "서울");
regions.put("BUSAN", "부산");
regions.put("JEJU", "제주");
return regions;
}
@ModelAttribute("itemTypes")
public ItemType[] itemTypes() {
return ItemType.values();
}
반응형