Notice
Recent Posts
Recent Comments
Link
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | ||||||
2 | 3 | 4 | 5 | 6 | 7 | 8 |
9 | 10 | 11 | 12 | 13 | 14 | 15 |
16 | 17 | 18 | 19 | 20 | 21 | 22 |
23 | 24 | 25 | 26 | 27 | 28 |
Tags
- 알고리즘
- springdatajpa
- Exception
- Thymeleaf
- Proxy
- http
- 백준
- 스프링
- kotlin
- SpringBoot
- QueryDSL
- Servlet
- transaction
- java
- AOP
- 그리디
- 김영한
- JPQL
- Spring Boot
- 자바
- 스프링 핵심 기능
- Greedy
- pointcut
- JDBC
- 인프런
- Android
- jpa
- spring
- 스프링 핵심 원리
- db
Archives
- Today
- Total
개발자되기 프로젝트
select box 본문
1. 셀렉트 박스
- 여러 선택지 중 하나를 선택하는 경우.
2. select 박스 추가
- 배송 방식
- 빠른 배송
- 일반 배송
- 느린 배송
- 셀렉트 박스로 하나만 선택이 가능.
3. Controller
- 자바 객체 사용.
@ModelAttribute("deliveryCodes")
public List<DeliveryCode> deliveryCodes(){
List<DeliveryCode> deliveryCodes = new ArrayList<>();
deliveryCodes.add(new DeliveryCode("FAST", "빠른 배송"));
deliveryCodes.add(new DeliveryCode("NORMAL", "일반 배송"));
deliveryCodes.add(new DeliveryCode("SLOW", "느린 배송"));
return deliveryCodes;
}
4. addForm.html
- default 값
- 아무 선택 안함
- <option value="">==배송 방식 선택==</option>
- 여러 옵션 생성
- th:each 활용.
<!-- SELECT -->
<div>
<div>배송 방식</div>
<select th:field="*{deliveryCode}" class="form-select">
<option value="">==배송 방식 선택==</option>
<option th:each="deliveryCode : ${deliveryCodes}" th:value="${deliveryCode.code}"
th:text="${deliveryCode.displayName}">FAST</option>
</select>
</div>
- item.html, editForm.html에도 적용
5. 결과
- 랜더링 결과
<!-- SELECT -->
<div>
<div>배송 방식</div>
<select class="form-select" id="deliveryCode" name="deliveryCode">
<option value="">==배송 방식 선택==</option>
<option value="FAST">빠른 배송</option>
<option value="NORMAL">일반 배송</option>
<option value="SLOW">느린 배송</option>
</select>
</div>
<hr class="my-4">
<div class="row">
<div class="col">
<button class="w-100 btn btn-primary btn-lg" type="submit">상품 등록</button>
</div>
<div class="col">
<button class="w-100 btn btn-secondary btn-lg"
onclick="location.href='/form/items'"
type="button">취소</button>
</div>
</div>
6. GitHub : 210923 select box
GitHub - bsh6463/Thymeleaf_Spring2
Contribute to bsh6463/Thymeleaf_Spring2 development by creating an account on GitHub.
github.com
'인프런 > [인프런] 스프링 MVC 2' 카테고리의 다른 글
Spring 메시지 소스 설정 (0) | 2021.09.24 |
---|---|
[Thymealef] 메시지, 국제화 (0) | 2021.09.24 |
라디오버튼, radio button (0) | 2021.09.23 |
체크박스 - 멀티 (0) | 2021.09.23 |
체크박스 - 단일 2 (0) | 2021.09.23 |
Comments