繁体   English   中英

在带有 Thymeleaf 和 Spring Boot 的嵌套类中使用枚举

[英]Using an enum within a nested class with Thymeleaf and Spring Boot

我有以下课程:

类型.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 中使用它们?

解决方案:

为了进入嵌套类,您需要在它们之间添加 $。 IE:

${T(jre.maintainme.utils.strings.Types$PC$Motherboard)}

对我有用的是你尝试的第一件事:

${T(com.my.package.path.Client.Type).values()

然而,IntelliJ 声称它无法解析 Type,但 IntelliJ说谎

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM