猿问

如何将多个参数从 thymeleaf html 传递给 thymeleaf 方言处理器

我正在创建一个自定义的百里香方言。我需要知道如何将参数从 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>

我可以','像"${parameter1,parameter2}"在 html 中那样将它分开,它工作正常,但我需要在我的处理器 [.java] 级别拆分。如果有任何其他方式我们可以在 html 级别实现它,这对我有帮助。


任何遇到过这种情况的人都可以有所启发。


汪汪一只猫
浏览 289回答 1
1回答

RISEBY

可以这样做:称呼:<th:block th:include="mailFragments::test('f1', 'f2', 'f3')"/>分段:&nbsp;<th:block th:fragment="test(p1,p2,p3)">&nbsp; &nbsp; <element dialectPrefix:customDialect="|${p1},${p2},${p3}|">тест</element>&nbsp;</th:block>和:&nbsp;new AbstractAttributeTagProcessor(TemplateMode.HTML, PREFIX, null, false, NAME, true, 1000, true) {&nbsp; &nbsp; @Override&nbsp; &nbsp; protected void doProcess(final ITemplateContext context, final ProcessableElementTag tag, final AttributeName name, String href, final IElementTagStructureHandler structureHandler) {&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; final IEngineConfiguration configuration = context.getConfiguration();&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; final IStandardExpressionParser parser = StandardExpressions.getExpressionParser(configuration);&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; final IStandardExpression categoryExpression = parser.parseExpression(context, value);&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; String delimitedResult = categoryExpression.execute(context).toString();&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; String[] params = delimitedResult.split(",");&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; .....&nbsp; &nbsp; }
随时随地看视频慕课网APP

相关分类

Java
我要回答