+ -
当前位置:首页 → 问答吧 → <s:if>取值怪异问题。

<s:if>取值怪异问题。

时间:2011-09-22

来源:互联网

<s:if test="instrumentReservation.timeA=='是'">
1
</s:if>
<s:elseif test="instrumentReservation.timeA=='否'">
2
</s:elseif>
<s:else>
3
s:else>

输出总是3
<s:if test="instrumentReservation.status=='待审核'">
1
</s:if>
<s:elseif test="instrumentReservation.timeA=='否'">
2
</s:elseif>
<s:else>
3
s:else>

这个能输出1. ${instrumentReservation.status } ${instrumentReservation.timeA } 都是可以取到值的。
timeA 和 status 都是 instrumentReservation 的属性啊,怎么一个能取出,一个就不能了呢?
这个timeA是后来加入instrumentReservation 这个类里面的属性。hibernate配置文件属性已经添加、属性get、set方法已经有了!

作者: w156445045   发布时间: 2011-09-22

你的这种情况我也遇到过,用el表达式可以取到,但是struts标签用el表达式取不到了,你试试用struts标签的取值方式,<s:if test="#域.对象.属性 eq 是">1</s:if>

作者: hgjcy520   发布时间: 2011-09-22

<s:if test="instrumentReservation.timeA=='是'">
1
</s:if>
<s:elseif test="instrumentReservation.timeA=='否'">
2
</s:elseif>
<s:else>
3
s:else>

在struts2中的字符串中,如果只有一个字符,则需要使用转义

\"否\"
否则会被认为是字符(而不是字符串)

作者: Fly_m   发布时间: 2011-09-22