我有以下代码:
<s:property value="currentPrice" />
<s:property value="oldPrice" />
<span class="badge">-50%</span>
现在我想显示 <span>
中的百分比按公式标记:
percentage = (currentPrice - oldPrice) / oldPrice * 100
如何在 Struts2 中做到这一点?
最佳答案
客户端解决方案:
<s:property value="currentPrice" />
<s:property value="oldPrice" />
<span class="badge">
<s:property value="%{((currentPrice - oldPrice) / oldPrice) * 100}" />%
</span>
或者替代地,
服务器端解决方案:
public Integer getPercentage(){
return ((currentPrice - oldPrice) / oldPrice) * 100;
}
<s:property value="currentPrice" />
<s:property value="oldPrice" />
<span class="badge">
<s:property value="percentage" />%
</span>
关于java - 使用 <s :property/> values in Struts2 进行计算,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33977795/