Thymeleaf
-
타임리프 - SpringEl(변수표현식)Thymeleaf 2022. 1. 19. 22:27
SpringEl 타임리프에서 제공하는 변수 표현식이다. Spring EL 표현식 Object ${user.username} = ${user['username']} ${user,getUsername()} = List ${users[0].username} = ${users[0]['username']} = ${users[0].getUsername()} = Map ${userMap['userA'].username} = ${userMap['userA']['username']} = ${userMap['userA'].getUsername()} = 결과 Object ${user.username} = UserA ${user['username']} UserA ${user,getUsername()} = UserA List ..
-
Thymeleaf 문법 정리Thymeleaf 2021. 12. 21. 18:53
th:field, th:error🎈 th:field="{필드 이름}"을 선언하면 HTML이 렌더링될 때, id, name을 같은 값으로 처리해준다. 즉, `th:field="{name}"은id = "name" name = "name"`과 같다 //fieldError 메소드를 미리 선언해서 에러 발생 시 빨간색 테두리가 호출되도록 설정 //th:field 예시 //테두리 빨간색 Incorrect date //에러메시지 출력th:object🎈 th:object는 폼에서 서버단으로 값을 넘길 때 object에 지정한 객체에 값을 담아 넘겨줄 수 있다. 즉, 화면에서 선언한 객체에 접근할 수 있게 된다. //th:object 예시 th:each🎈 해당 객체에 담긴 값들을 콜렉션 형식으로 가져올 수 있다. //t..
-
th:replaceThymeleaf 2021. 12. 21. 00:01
th:replace th:replace는 fragment와 함께 쓰이며, fragment 파일 아래에 선언해놓은 html 파일이 치환되는 방식이다. //home.html 위 처럼 home.html에 th:replace를 선언하고 "fragments/header"를 선언해서 경로를 지정해 주면 "fragments/header" 경로에 위치한 파일이 치환되어 실행된다. 자주 사용되는 레이아웃을 적용시킬 때 사용하는 방식인데, 위와 같은 방식은 Include-style layouts 방식이고, old한 방식이며 비효율적이다. Hierarchical-style layouts 방식으로 레이아웃 치환을 더욱 효율적으로 처리할 수 있다. thymeleaf.org/doc/articles/layouts.html 경로에 ..