Thymeleaf
[Thymeleaf] 배열 데이터 each 없이 한번에 표현
유저인사이트 박준호
2022. 8. 19. 10:23
728x90
public enum AttendanceReportReason {
NONE("해당없음", "0",
new AttendanceStudentType[]{AttendanceStudentType.ATTEND, AttendanceStudentType.ABSENT}),
`
`
`
OMISSION("누락", "1", new AttendanceStudentType[]{AttendanceStudentType.ATTEND_CORRECTION,
AttendanceStudentType.LEAVE_CORRECTION}),
private String text;
private String value;
private AttendanceStudentType[] reportType;
}
view에서 AttendanceReportReason 이라는 enum 클래스의 요소들을 select의 option들로 사용하는 과정에서
AttendanceStudentType []의 배열 데이터를 한 옵션 안에 표현하는데 문제가 생겼다.
해결
<option th:each="r : ${reason.values()}" th:data-type="${{r.reportType}}"></option>
배열 데이터를 중괄호로 한번 더 묶으면 쉽게 해결된다.
- 중괄호로 묶지 않았을 때
- 중괄호로 한번 더 묶었을 때
참고: https://www.thymeleaf.org/doc/tutorials/2.1/thymeleafspring.html#listing-seed-starter-data
Tutorial: Thymeleaf + Spring
Preface This tutorial explains how Thymeleaf can be integrated with the Spring Framework, especially (but not only) Spring MVC. Note that Thymeleaf has integrations for both versions 3.x and 4.x of the Spring Framework, provided by two separate libraries c
www.thymeleaf.org
박준호 / 선임연구원
Junho Park / 서비스R&D팀
728x90