Thymeleaf allows a signature of a fragment without explicit parameters like this:
<div th:fragment="my_fragment">
<p th:text="${content}"></p>
<p th:text="${defaultParameter}"></p>
</div>
To call this fragment and pass content
and defaultParameter
you may call the fragment as follows:
<!-- both parameters not specified -->
<div th:replace="fragments :: my_fragment"></div>
<!-- only content parameter specified -->
<div th:replace="fragments :: my_fragment(content='a')"></div>
<!-- both parameters specified -->
<div th:replace="fragments :: my_fragment(content='a', defaultParameter='b')"></div>
But the below will not work:
<div th:replace="fragments :: my_fragment('a', 'b')"></div>
And the message is self-explonatory:
Signature "my_fragment" declares no parameters, but fragment selection did specify parameters in a synthetic manner (without names), which is not correct due to the fact parameters cannot be assigned names unless signature specifies these names.
So in case you want to maintain backward compatibility, you should use named parameters while calling a fragment and do not specify parameters in a signature of a fragment.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…