【发布时间】:2023-03-15 00:48:01
【问题描述】:
我正在创建一个自定义的百里香方言。我需要知道如何将参数从 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 }
如果我想从 thymeleaf html 传递多个参数,如下所示
<th:block dialectPrefix:customDialect="${parameter1}" "${parameter2} etc"> </th:block>
我可以通过',' 将它分开,就像 html 中的"${parameter1,parameter2}" 一样,它工作正常,但我需要在我的处理器[.java] 级别进行拆分。如果有任何其他方式我们可以在 html 级别实现这对我有帮助。
任何遇到过这种情况的人都可以有所启发。
【问题讨论】:
-
本机不支持此功能。您可以在code for
th:with(它支持多个赋值)中看到它只是在处理表达式并拆分输入本身。 -
嗨,Metroids 感谢您的输入。您能否将 thymleaf html 代码粘贴给我,以便在 doProcess 方法中解析 AssignationUtils 序列?