설명서를 읽었지만 여전히 약간 혼란 스럽습니다. index.html이라는 템플릿이 있다고 가정 해 보겠습니다. index.html 내부에서 요청을 기반으로 조각으로 컨테이너 태그를 업데이트하려고합니다. 여기 내 조각이 searchResult.html라고 : 스프링 부트 Thymeleaf는 뷰 빈 대신 컨트롤러에서 파생됩니다.
<html lang="en" xmlns:th="http://www.thymeleaf.org">
<body>
<div th:fragment="searchResult">
</div>
</body>
</html>
나는이 조각은 index.html을 내부에 특정 태그 내부에 표시하려면
는 어떻게이 컨트롤러에서해야합니까?@RequestMapping("/")
public String showIndex(){
return "index";
}
@RequestMapping("/search")
public String search(){
return "index :: searchResult";
}
showIndex()에서는 조각을 제외한 모든 것을 표시하려고합니다. search()에 매핑 된 get 요청 중에 fragment를 포함한 전체 인덱스를 반환하려고합니다. 템플릿과 컨트롤러는 어떻게 생겼을 까?
템플릿 : 대부분의 경우
<html>
<body>
<div>Usual content shown all the time</div>
<div id="searchResult">
THIS IS WHERE I WANT THE FRAGMENT TO BE INJECTED
</div>
</body>
</html>
아니면 검색 결과를 모델에 추가하고 인덱스를 새로 고치면됩니다. 대신에 다음과 같은 조건부 유틸리티 클래스를 사용하여 마크 업을 할 수 있습니다 : unless = "$ {# lists.isEmpty()}"? – knerlington