我想在select选项(Thymeleaf)中添加一个th:text,
<option th:each="case : ${caseCategoryList}" th:value="${case.caseCategoryId}" th:text="${case.caseCategoryName} - ${case.caseCategoryCode}"></option>
但我收到此错误
08:28:05,501 ERROR [[servlet-context]] Servlet.service() for servlet servlet-context threw exception
org.thymeleaf.exceptions.TemplateProcessingException: Cannot execute subtraction: operands are "INPATIENT" and "IP" (memberrki/member-rki-form:124)
at org.thymeleaf.standard.expression.SubtractionExpression.executeSubtraction(SubtractionExpression.java:91)
at org.thymeleaf.standard.expression.ComplexExpression.executeComplex(ComplexExpression.java:58)
at org.thymeleaf.standard.expression.Expression.execute(Expression.java:107)
at org.thymeleaf.standard.expression.Expression.execute(Expression.java:133)
at org.thymeleaf.standard.expression.Expression.execute(Expression.java:120)
at org.thymeleaf.standard.processor.attr.AbstractStandardTextChildModifierAttrProcessor.getText(AbstractStandardTextChildModifierAttrProcessor.java:68)
at org.thymeleaf.processor.attr.AbstractTextChildModifierAttrProcessor.getModifiedChildren(AbstractTextChildModifierAttrProcessor.java:59)
at org.thymeleaf.processor.attr.AbstractChildrenModifierAttrProcessor.processAttribute(AbstractChildrenModifierAttrProcessor.java:58)
at org.thymeleaf.processor.attr.AbstractAttrProcessor.doProcess(AbstractAttrProcessor.java:87)
at org.thymeleaf.processor.AbstractProcessor.process(AbstractProcessor.java:212)
at org.thymeleaf.dom.Node.applyNextProcessor(Node.java:1016)
at org.thymeleaf.dom.Node.processNode(Node.java:971)
...
你可以帮我解决这个错误,
答案 0 :(得分:1)
Thymeleaf正在解释这个:th:text="${case.caseCategoryName} - ${case.caseCategoryCode}"
,因为从caseCategoryName中减去caseCategoryCode的值,以显示结果。
并且,由于这些是String值,因此减法失败。
我怀疑你根本不想减去它们,而是想要显示用连字符分隔的两个vaues。像这样:
INPATIENT - IP
要做到这一点,你可以转义连字符,以便Thymeleaf不将它视为减法运算符:
th:text="${case.caseCategoryName} - ${case.caseCategoryCode}"
答案 1 :(得分:1)
按照glytching的建议使用-
对我不起作用。但是,这可行:
th:text="${case.caseCategoryName} + '-' + ${case.caseCategoryCode}"