freemarker写select组件
1、宏定义
<#macro select id datas value="" key="" text="" headKey="" headValue="">
<select id="${id}" name="${id}">
<option>---请选择---</option>
<#if headKey!="">
<option value="${headKey}">${headValue}</option>
</#if>
<#list datas as data>
<#if key!="">
<#if value == data[key]?string>
<option value="${data[key]}" selected>${data[text]}</option>
<#else>
<option value="${data[key]}">${data[text]}</option>
</#if>
<#else>
<#if value == data>
<option value="${data}" selected>${data}</option>
<#else>
<option value="${data}">${data}</option>
</#if>
</#if>
</#list>
</select>
</#macro>
2、引入宏
<@items.select id="username" datas=users key="userNo" text="userName" headKey="0" headValue="其他"/>
3、示例结果
<select id="username" name="username">
<option>---请选择---</option>
<option value="0">其他</option>
<option value="1">张三丰</option>
<option value="2">李思思</option>
<option value="3">赵武</option>
<option value="4">刘雪</option>
<option value="5">朱顾</option>
<option value="6">赵武</option>
<option value="7">吴语</option>
<option value="8">血玉</option>
</select>