如何在Struts 2中串联2个动作类变量? [英] How to concatenate 2 action class variables in Struts 2?

查看:106
本文介绍了如何在Struts 2中串联2个动作类变量?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的动作类中有2个变量,分别为id1id2.通过_加入后,它们被用作地图键.

I have 2 variable in my action class, id1 and id2. Joined by a _, they're used as a map key.

我无法使用以下代码检索地图值:

I am not able to retrieve the map value using this code:

<s:property value="%{mymap[id1_id2]}" /> 

我应该如何检索地图值?

How should I retrieve the map value?

推荐答案

OGNL中的表达式id1_id2将假定存在名为id1_id2的变量,因为它是完全合法的标识符.

The expression id1_id2 in OGNL will assume the presence of a variable named id1_id2, since it's a perfectly legal identifier.

如果要连接字符串,则需要:

If you want to concatenate strings, you'd need:

<s:property value="%{mymap[id1 + '_' + id2]}" />

我可能会创建一个单独的变量用作键:

I'd likely create a separate variable to use as the key:

<s:set var="mapKey" value="%{id1 + '_' + id2}" />
<s:property value="%{mymap[#mapKey]}" />

或更可能的是,我会在视图层之外的其他地方这样做.

Or more likely, I'd do it somewhere besides the view layer.

这篇关于如何在Struts 2中串联2个动作类变量?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆