Struts2 什么';s支柱';S2相当于Struts 1逻辑:空标记?
Struts 2与Struts 1逻辑的等价物是什么:空标记Struts2 什么';s支柱';S2相当于Struts 1逻辑:空标记?,struts2,Struts2,Struts 2与Struts 1逻辑的等价物是什么:空标记 <logic:empty name="foo"> Foo is null or the empty string </logic:empty> Foo为null或空字符串 谢谢。没有struts2标记可以做到这一点,OGNL比struts1标记有更多的可能性和更高的表现力,但是似乎没有一种方法可以简洁地检查字符串的null和空字符串 以下工作: <s:if test="(myString ==
<logic:empty name="foo">
Foo is null or the empty string
</logic:empty>
Foo为null或空字符串
谢谢。没有struts2标记可以做到这一点,OGNL比struts1标记有更多的可能性和更高的表现力,但是似乎没有一种方法可以简洁地检查字符串的null和空字符串 以下工作:
<s:if test="(myString == null || myString.equals(''))">
myString is blank or null
</s:if>
<s:else>
The value is <s:property value="myString"/>
</s:else>
myString为空或null
价值是
该测试依赖于短循环,因此null测试不能随相等性测试而更改
如果经常需要对其进行测试,则可能存在设计问题。有了适当的验证,就不应该有视图所依赖的未初始化对象,但我想总会有例外 要添加到四元数的答案中:
MyAction.isPropertyXEmpty()
并将其置于
条件中要扩展Steven的评论,可以使用导入
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
然后使用:
<c:if test="${empty myStruts2Var}">
或
对于字符串,我将使用:
<s:if test="myString in {null, ''}">
<s:if test="null == myCollection || myCollection.empty">
对于集合,我将使用:
<s:if test="myString in {null, ''}">
<s:if test="null == myCollection || myCollection.empty">
希望这有利于可读性。JSTL if或choose/when/other也是一个不错的选择。这个问题仍然存在吗?