gpt4 book ai didi

java - 带有数学函数的 Struts2 标签

转载 作者:行者123 更新时间:2023-12-02 08:05:04 26 4
gpt4 key购买 nike

我使用struts2并想在struts标签中使用Math.max方法。像这样:

<s:property value="%{Math.max( 1 , 5 ) }" />

或者:

<s:set var="pfrom" value="%{Math.max( 1 , page - 5 )}" /> 

但是这个代码不起作用。

最佳答案

请参阅 accessing static properties 的文档.

简而言之:%{@java.lang.Math@max(...)}

您需要在 Struts 配置文件中配置允许静态访问:

<constant name="struts.ognl.allowStaticMethodAccess" value="true" />

不过,如果可能的话,我强烈建议您在行动中进行类似的工作。 “哑” View 更容易测试—— Controller 中的逻辑越多,事情就越容易。

相同的逻辑可以作为操作方法公开。

关于java - 带有数学函数的 Struts2 标签,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8298596/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com