freemarker遍历enum 示例:
enum
package com.xxx;
public enum BooleanEnum {
TRUE(Boolean.TRUE, "是"), FALSE(Boolean.FALSE, "否");
private final Boolean value;
private final String info;
private BooleanEnum(Boolean value, String info) {
this.value = value;
this.info = info;
}
public String getInfo() {
return info;
}
public Boolean getValue() {
return value;
}
}
在controller或者interceptor中,将freemarker的包装类添加到model中:
model.addObject("enums", BeansWrapper.getDefaultInstance()
.getEnumModels());
页面上即可进行遍历
<select>
<#list enums["com.xxx.BooleanEnum"]?values as item>
<option value="${item}">${item.info}</option>
</#list>
<option value="">全部</option>
</select>