我正在创造一个定制的thymeleaf dilect。我需要知道如何将参数从thymleaf html片段传递到dielect处理器。我能够实现一个参数,但我需要知道我们将如何实现多个参数。下面是我的百里叶片段。
<th:block dialectPrefix:customDialect="${parameter}"> </th:block>
以下是我的处理器逻辑
protected void doProcess(final ITemplateContext context, final IProcessableElementTag tag, final AttributeName attributeName, final String attributeValue, final IElementTagStructureHandler structureHandler) { final IEngineConfiguration configuration = context.getConfiguration(); final IStandardExpression categoryExpression = parser.parseExpression(context, someString); final IStandardExpressionParser parser = StandardExpressions.getExpressionParser(configuration); String fetchValue=categoryExpression.execute(context).toString() //I am able to get the value of parameter }
如果我想从百万富翁html传递多个参数,如下所示
<th:block dialectPrefix:customDialect="${parameter1}" "${parameter2} etc"> </th:block>
我可以通过','
将它与"${parameter1,parameter2}"
分开,在html中它工作正常,但我需要拆分处理器[.java]级别。如果有任何其他方式,我们可以在html级别实现,这将有助于我。
遇到这种情况的任何人都可以解释一下。
它可以这样做:
呼叫:
<th:block th:include="mailFragments::test('f1', 'f2', 'f3')"/>
分段:
<th:block th:fragment="test(p1,p2,p3)">
<element dialectPrefix:customDialect="|${p1},${p2},${p3}|">тест</element>
</th:block>
和:
new AbstractAttributeTagProcessor(TemplateMode.HTML, PREFIX, null, false, NAME, true, 1000, true) {
@Override
protected void doProcess(final ITemplateContext context, final ProcessableElementTag tag, final AttributeName name, String href, final IElementTagStructureHandler structureHandler) {
final IEngineConfiguration configuration = context.getConfiguration();
final IStandardExpressionParser parser = StandardExpressions.getExpressionParser(configuration);
final IStandardExpression categoryExpression = parser.parseExpression(context, value);
String delimitedResult = categoryExpression.execute(context).toString();
String[] params = delimitedResult.split(",");
.....
}
PS:对于定制的百日咳标签,请参阅Say Hello! Extending Thymeleaf in 5 minutes