【发布时间】:2021-01-23 17:01:59
【问题描述】:
我有以下课程:
Types.java:
public class Types {
public static class PC {
public static enum Motherboard {
OPTION1("option 1"),
OPTION2("option 2"),
OPTION3("option 3");
private final String displayValue;
private Motherboard(String displayValue) { this.displayValue = displayValue; }
public String getDisplayValue() { return this.displayValue; }
}
};
};
在我的 Thymeleaf 模板中,我有:
<select name="select-motherboard">
<option th:each="size : ${T(jre.maintainme.utils.strings.Types.PC.Motherboard).values()}" th:value="${size}" th:text="${size.displayValue}"></option>
</select>
但是,这似乎不起作用。但是,如果我将 Motherboard 枚举放入 Types 类中,它确实...有没有一种方法可以将枚举嵌套在类中并在 Thymeleaf 中使用它们?
【问题讨论】:
-
嗯。那应该工作得很好。如果你运行
System.out.println(OPTION1.getClass())会发生什么? -
它带有
class jre.maintainme.utils.strings.Types$PC$Motherboard编辑:想通了。我最初使用 # 来区分类,还有 .但正确的是刚才指出的是在类之间使用 $。 -
在 Stack Overflow 上,不要用正确的答案编辑你的问题,而是发布你自己问题的答案(你甚至可以接受它)。
标签: java spring spring-boot thymeleaf