現在機能している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」を動的にできるようにしたい。「parse」パラメーターの有無にかかわらず、次のことを試しました。
<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 にゲッターを追加しました。
public String getJsonPrefix() {
return "test";
}
ただし、結果の JSON は次のようになります。
${jsonPrefix}&&{ ... }
json の結果の型は、そのパラメーターで OGNL 式を解析できませんか? エフェクトを作成するために他の構成が必要ですか? カスタム JSON 文字列全体を作成するのではなく、既存の (または) オブジェクト モデルから JSON への自動変換を使用したいと考えています。