在普通的jsp页面中使用EL 和三目运算 如下
<a href="https://www.baidu.com" target="_blank" style="${1 == 1 ? 'color:yellow' : ''}">百度</a>
若在freemark中可以采用如下语法
用freemarker时写三目运算,开始一直这样写,${true?3:4}, 不行,再换成: ${true?'3':'4'},汗,还是不行,然后想起freemarker输出字符串后面要带上?string,
所以又写上${true?'3'string:'4'string},汗,其实需要这样写 ${true?string('5','7')}
案例如下
style="${news.red ? string('color:red;' , '')}${news.bold ? string('font-weight:bold;' , '')}"
若要在EL表达式中使用两个变量拼接字符串,则如下
<a href="${expiringNo>0?ctx+'/protocol/list?mytask=6' :'javascript:void(0);'}">
<font color="#FF0000" size="5">${expiringNo}</font>
</a>个。
结果“+”直接输出了,没有连