나는 모두 추상 기본 클래스를 공유하는 양식지지 오브젝트를 사용합니다. 이 기본 클래스의 속성 중 하나는 model
이지만 내 도메인 모델의 엔터티는 무엇이든 나타낼 수 있습니다.양식에서 Thymeleaf 로컬 변수를 사용하는 올바른 방법
지금 내가하고 싶은 것이 즉 curriculum
, advertisement
등, 따라서 내 다른 Thymeleaf 템플릿 model
보다 advertisement
와 더 좋은 읽을 것입니다 내 개체의 이름으로 model
속성을 이름을 변경하기 위해 th:with
를 사용합니다. 여기
<form th:object="${advertisementForm}" th:with="advertisement=*{model}" th:action="@{${postUrl}}" method="post" class="form-horizontal">
(model
이 advertisementForm
의 한 속성입니다) 다음과 같이 그때 내 새로 만든 advertisement
변수에 액세스하려고 할 때 :
<input type="hidden" th:field="${advertisement.id}"/>
다음과 같이 표시됩니다.
java.lang.IllegalStateException: Neither BindingResult nor plain target object for bean name 'advertisement' available as request attribute
로컬 변수가 사용되지 않음을 나타냅니다.