프로젝트 정리/스프링과 JPA 기반 웹 애플리케이션 개발
15. 뷰 중복 코드 제거
JunGi Jeong
2021. 4. 1. 00:48
타임리프 프레그먼트 (Fragement) 사용하기
- www.thymeleaf.org/doc/tutorials/3.0/usingthymeleaf.html#including-template-fragments
- 프레그먼트 정의
- th:fragement
- 프레그먼트 사용
- th:insert
- th:replace
뷰 중복 코드 ( 이를 fragement로 만들어서 재사용 할 것)
- 메인 네비게이션
- 하단 (footer)
- 헤더 (head)
fragement -> 재사용 조각
th:replace="fragements.html :: main-nav" -> 파일의 directory 아래의 경로로 찾음 full 경로가 필요
아래와 같이 사용했더니 thymeleaf and security에러
<a class="dropdown-item" href="#" th:href="@{'/profile/' + ${#authentication.name}">프로필</a>
-> 바꿔서 해결 오타조심
<a class="dropdown-item" href="#" th:href="@{'/profile/' + ${#authentication.name}}">프로필</a>