如何用Thymeleaf显示枚举的一个值

时间:2016-08-02 12:57:46

标签: java enums thymeleaf

我的枚举:

public enum USER_TYPE { administrator, manager, worker };

        private GENDER gender;

我的HTML:

<div class="form-group">
            <label class="col-sm-2 control-label"> User type:</label>
             <div class="col-xs-5 selectContainer">
             <select class="form-control" name="size" th:field="*{userType}">
                <option  th:each="userType : ${T(com.people.User.USER_TYPE).values()}" th:value="${userType}" th:text="${userType}"></option>


            </select>

我设法显示枚举的所有值,但是如何只显示管理员值?

1 个答案:

答案 0 :(得分:1)

<option th:value="${T(com.people.User.USER_TYPE).manager}" 
        th:text="${T(com.people.User.USER_TYPE).manager}"></option>