当前位置: 代码迷 >> 综合 >> Thymeleaf模板引入遍历枚举
  详细解决方案

Thymeleaf模板引入遍历枚举

热度:53   发布时间:2023-11-02 01:23:47.0

1.Enum 代码

package com.java.enums;
public enum SerialEnum {
    A(1, "A"),
    B(2, "B"),
    C(3, "C");


    public String key;
    public String value;


    public String getKey() {
        return key;
    }
    public String getValue() {
        return value;
    }
 
    AreaSerialEnum(String key, String value) {
        this.key = key;
        this.value = value;
    }
}
 

2.Thymeleaf模板遍历枚举键值

<select>
  <option th:each="enmu : ${T(com.java.enums.SerialEnum).values()}"

              th:value="${enmu.key}"

              th:text="${enmu.value}">

   </option>
</select>