jstl+el 获取枚举元素

来源:互联网 发布:网络延迟测试在线 编辑:程序博客网 时间:2024/06/02 01:13

新手笔记:

//枚举

   public enum AttributeType {
        text, number, alphaint, select, checkbox, date

    }


// 获取所有商品属性类型
    public List<AttributeType> getAllAttributeType() {
        List<AttributeType> allAttributeType = new ArrayList<AttributeType>();
        for (AttributeType attributeType : AttributeType.values()) {
            allAttributeType.add(attributeType);
        }
        return allAttributeType;
    }


在jsp页面上使用jstl

<select id="productAttributeType" name="productAttribute.attributeType" >
                            <option value="">请选择...</option>                                              
                            <c:forEach items="${allAttributeType}" var="list">
                                <option value="list">
                                    ${list}
                                </option>
                            </c:forEach>
 </select>

原创粉丝点击