我只是看不到它.我想做相同的以下内容:
listValue="%{capitalize(remoteUserName)}"
Run Code Online (Sandbox Code Playgroud)
在s:select标签内.
根据struts文档http://struts.apache.org/2.0.11.2/struts2-core/apidocs/com/opensymphony/xwork2/inject/util/Strings.html,存在一个大写函数.我已经尝试了上面的两个和Strings.capitalize来尝试大写remoteUserName.
徘徊在http://incubator.apache.org/ognl/上的OGNL文档遗留下来的内容,我没有看到立即以这种方式利用的方法.
那么当使用struts 2标签时,什么是大写的语法呢?
编辑:
我意识到我提出的想法是将这个词的第一个字母大写.真的,我希望单词中的每个字符都大写.
以下是使用com.opensymphony.xwork2.inject.util.Strings的示例(已经过测试)
<s:property value="@com.opensymphony.xwork2.inject.util.Strings@capitalize(myString)"/>
Run Code Online (Sandbox Code Playgroud)
这需要启用静态方法调用,这样做只需添加,
<struts>
<constant name="struts.ognl.allowStaticMethodAccess" value="true"/>
</struts>
Run Code Online (Sandbox Code Playgroud)
进入struts.xml
编辑:就像其他人知道的那样(你可能已经这样做了)你可以使用java.lang.String的任何方法,即:myString.toUpperCase()是一个有效的表达式,你可以使用正则表达式和java.lang.String方法replaceFirst或replaceAll来实现所需的结果.
如果com.opensymphony.xwork2.inject.util.Strings capitalize方法不能满足您的需求,则此问题将涵盖其他可能有用的方法:如何将字符串中每个单词的第一个字符大写
| 归档时间: |
|
| 查看次数: |
2248 次 |
| 最近记录: |