需求:在工做中解決的一些問題感受不夠「優美」。因此把這些問題貼出來,但願有更好操做的大牛不吝賜教。前端
第一問:Freemarker模擬「三元表達式」功能json
答: ${(orderpaydetail.loginViewList[0] = "390")?string('醫療保險','養老保險')}數組
第二問:Freemarker 獲得前端字符串中英文分割的數字並遍歷,格式以下:字符串
A100B200C350D490E530F690G770H890string
答: <!-- 替換返回中的英文爲「,」,方便後期將字符串轉爲集合 -->
<#assign Source=(orderpaydetail.attributeItems['hth'])>
<#assign FirstGrade=Source?replace('A', '', 'i')?replace('B', ',', 'i')?replace('C', ',', 'i')?replace('D', ',', 'i')?replace('E', ',', 'i')?replace('F', ',', 'i')>
<#assign SecondGrade=FirstGrade?replace('G', ',', 'i')?replace('H', ',', 'i')?replace('I', ',', 'i')?replace('J', ',', 'i')?replace('K', ',', 'i')?replace('L', ',', 'i')>
<#assign ThirdGrade=SecondGrade?replace('M', ',', 'i')?replace('N', ',', 'i')?replace('O', ',', 'i')?replace('P', ',', 'i')?replace('Q', ',', 'i')?replace('R', ',', 'i')>
<#assign FourthGrade=ThirdGrade?replace('S', ',', 'i')?replace('T', ',', 'i')?replace('U', ',', 'i')?replace('V', ',', 'i')?replace('W', ',', 'i')?replace('X', ',', 'i')>
<#assign FifthGrade=FourthGrade?replace('Y', ',', 'i')?replace('Z', ',', 'i')>it
<select id="payGrade">
<option value="0">請選擇</option>
<#list FifthGrade?split(",") as grade>
<option value="${grade}" >
${grade}元</option>
</#list>io
</select>List
第三問:Freemarker遍歷json數組select
答: <#list [{"ysls":"2017122101","sfny":"201712"},{"ysls":"2017122234","sfny":"201734"}] as json> ${(json['ysls'])!''} ${(json['sfny'])!''}</#list>遍歷