0

我有一个带有 json 结果类型的 struts2 操作,该操作当前正在运行。我也能够成功添加静态“wrapPrefix”:

<action name="example_*" class="example.ExampleAction" method="{1}">
    <result name="success" type="json">
        <param name="wrapPrefix">test</param>
    </result>
    <result name="error" type="chain">jsonError</result>            
</action>

正如预期的那样,example_list.action 的 JSON 结果是(其中 { ... } 表示原始结果 JSON):

测试{ ... }

我希望能够使“wrapPrefix”动态化。我已经尝试了以下,无论是否有“解析”参数:

<action name="example_*" class="example.ExampleAction" method="{1}">
    <result name="success" type="json">
        <param name="parse">true</param>
        <param name="wrapPrefix">${jsonPrefix}</param>
    </result>
    <result name="error" type="chain">jsonError</result>            
</action>

在 ExampleAction 中,我添加了 getter:

public String getJsonPrefix() {
    return "test";
}

但是,现在生成的 JSON 是:

${jsonPrefix}&&{ ... }

json 结果类型可以不解析其参数中的 OGNL 表达式吗?是否需要一些其他配置来创建效果?我想使用(或)现有的自动对象模型到 JSON 的转换,而不是创建整个自定义 JSON 字符串。

4

2 回答 2

0

更正:第二个(无效)JSON 结果是:

${jsonPrefix}{ ... }

于 2010-12-07T01:05:44.920 回答
0

json 结果类型可以不解析其参数中的 OGNL 表达式吗?

不,它无法解析其任何参数中的 OGNL 表达式。您可以尝试对其进行子类化,但老实说,您可能更容易制作该类的本地副本并直接修改它,因为它不是为扩展而设计的。

于 2010-12-07T01:54:48.783 回答