我想要实现的目标很简单:
<form action="/matrix/${matrix.name}/add-task">
但是我无法让Thymeleaf将matrix.name
的值放入我的表单中。
我尝试了th:inline
:
<form th:inline="text" action="/matrix/[[${matrixName}]]/add-task">
th:with
:
<form th:with="matrixName=${matrix.name}" action="/matrix/${matrixName}/add-task">
th:action
:
<form th:action="@{/matrix/__${matrix.name}__/add-task">
但没有任何作用。值保持${matrix.name}
并且不会被替换,或者在后一种情况下(th:action
)我得到一个例外:
11:31:58 PM web.1 | [qtp344749160-16] ERROR org.thymeleaf.TemplateEngine - [THYMELEAF][qtp344749160-16] Exception processing template "matrix": Could not parse as expression: "@{/matrix/__${matrix.name}__/add-task" (matrix:111)
11:31:58 PM web.1 | [qtp344749160-16] ERROR spark.webserver.MatcherFilter -
11:31:58 PM web.1 | org.thymeleaf.exceptions.TemplateProcessingException: Could not parse as expression: "@{/matrix/__${matrix.name}__/add-task" (matrix:111)
11:31:58 PM web.1 | at org.thymeleaf.standard.expression.StandardExpressionParser.parseExpression(StandardExpressionParser.java:186)
11:31:58 PM web.1 | at org.thymeleaf.standard.expression.StandardExpressionParser.parseExpression(StandardExpressionParser.java:70)
11:31:58 PM web.1 | at org.thymeleaf.standard.expression.StandardExpressionParser.parseExpression(StandardExpressionParser.java:40)
11:31:58 PM web.1 | at org.thymeleaf.standard.processor.attr.AbstractStandardSingleAttributeModifierAttrProcessor.getTargetAttributeValue(AbstractStandardSingleAttributeModifierAttrProcessor.java:65)
11:31:58 PM web.1 | at org.thymeleaf.processor.attr.AbstractSingleAttributeModifierAttrProcessor.getModifiedAttributeValues(AbstractSingleAttributeModifierAttrProcessor.java:59)
11:31:58 PM web.1 | at org.thymeleaf.processor.attr.AbstractAttributeModifierAttrProcessor.processAttribute(AbstractAttributeModifierAttrProcessor.java:61)
11:31:58 PM web.1 | at org.thymeleaf.processor.attr.AbstractAttrProcessor.doProcess(AbstractAttrProcessor.java:87)
11:31:58 PM web.1 | at org.thymeleaf.processor.AbstractProcessor.process(AbstractProcessor.java:212)
11:31:58 PM web.1 | at org.thymeleaf.dom.Node.applyNextProcessor(Node.java:1016)
11:31:58 PM web.1 | at org.thymeleaf.dom.Node.processNode(Node.java:971)
11:31:58 PM web.1 | at org.thymeleaf.dom.NestableNode.computeNextChild(NestableNode.java:672)
11:31:58 PM web.1 | at org.thymeleaf.dom.NestableNode.doAdditionalProcess(NestableNode.java:655)
11:31:58 PM web.1 | at org.thymeleaf.dom.Node.processNode(Node.java:990)
11:31:58 PM web.1 | at org.thymeleaf.dom.NestableNode.computeNextChild(NestableNode.java:672)
11:31:58 PM web.1 | at org.thymeleaf.dom.NestableNode.doAdditionalProcess(NestableNode.java:655)
11:31:58 PM web.1 | at org.thymeleaf.dom.Node.processNode(Node.java:990)
11:31:58 PM web.1 | at org.thymeleaf.dom.NestableNode.computeNextChild(NestableNode.java:672)
11:31:58 PM web.1 | at org.thymeleaf.dom.NestableNode.doAdditionalProcess(NestableNode.java:655)
11:31:58 PM web.1 | at org.thymeleaf.dom.Node.processNode(Node.java:990)
11:31:58 PM web.1 | at org.thymeleaf.dom.NestableNode.computeNextChild(NestableNode.java:672)
11:31:58 PM web.1 | at org.thymeleaf.dom.NestableNode.doAdditionalProcess(NestableNode.java:655)
11:31:58 PM web.1 | at org.thymeleaf.dom.Node.processNode(Node.java:990)
11:31:58 PM web.1 | at org.thymeleaf.dom.Document.process(Document.java:93)
11:31:58 PM web.1 | at org.thymeleaf.TemplateEngine.process(TemplateEngine.java:1155)
11:31:58 PM web.1 | at org.thymeleaf.TemplateEngine.process(TemplateEngine.java:1060)
11:31:58 PM web.1 | at org.thymeleaf.TemplateEngine.process(TemplateEngine.java:1011)
11:31:58 PM web.1 | at org.thymeleaf.TemplateEngine.process(TemplateEngine.java:924)
11:31:58 PM web.1 | at org.thymeleaf.TemplateEngine.process(TemplateEngine.java:898)
11:31:58 PM web.1 | at spark.template.thymeleaf.ThymeleafTemplateEngine.render(ThymeleafTemplateEngine.java:75)
11:31:58 PM web.1 | at spark.TemplateViewRouteImpl$1.render(TemplateViewRouteImpl.java:61)
11:31:58 PM web.1 | at spark.TemplateViewRouteImpl$1.render(TemplateViewRouteImpl.java:58)
11:31:58 PM web.1 | at spark.TemplateViewRouteImpl.render(TemplateViewRouteImpl.java:85)
11:31:58 PM web.1 | at spark.webserver.MatcherFilter.doFilter(MatcherFilter.java:164)
11:31:58 PM web.1 | at spark.webserver.JettyHandler.doHandle(JettyHandler.java:61)
11:31:58 PM web.1 | at org.eclipse.jetty.server.session.SessionHandler.doScope(SessionHandler.java:189)
11:31:58 PM web.1 | at org.eclipse.jetty.server.handler.ScopedHandler.handle(ScopedHandler.java:141)
11:31:58 PM web.1 | at org.eclipse.jetty.server.handler.HandlerList.handle(HandlerList.java:52)
11:31:58 PM web.1 | at org.eclipse.jetty.server.handler.HandlerWrapper.handle(HandlerWrapper.java:119)
11:31:58 PM web.1 | at org.eclipse.jetty.server.Server.handle(Server.java:517)
11:31:58 PM web.1 | at org.eclipse.jetty.server.HttpChannel.handle(HttpChannel.java:302)
11:31:58 PM web.1 | at org.eclipse.jetty.server.HttpConnection.onFillable(HttpConnection.java:242)
11:31:58 PM web.1 | at org.eclipse.jetty.io.AbstractConnection$ReadCallback.succeeded(AbstractConnection.java:245)
11:31:58 PM web.1 | at org.eclipse.jetty.io.FillInterest.fillable(FillInterest.java:95)
11:31:58 PM web.1 | at org.eclipse.jetty.io.SelectChannelEndPoint$2.run(SelectChannelEndPoint.java:75)
11:31:58 PM web.1 | at org.eclipse.jetty.util.thread.strategy.ExecuteProduceConsume.produceAndRun(ExecuteProduceConsume.java:213)
11:31:58 PM web.1 | at org.eclipse.jetty.util.thread.strategy.ExecuteProduceConsume.run(ExecuteProduceConsume.java:147)
11:31:58 PM web.1 | at org.eclipse.jetty.util.thread.QueuedThreadPool.runJob(QueuedThreadPool.java:654)
11:31:58 PM web.1 | at org.eclipse.jetty.util.thread.QueuedThreadPool$3.run(QueuedThreadPool.java:572)
11:31:58 PM web.1 | at java.lang.Thread.run(Thread.java:745)
Thymeleaf让我发疯。如何使用简单的变量内联来使用此模板引擎?