我有以下实现
public abstract class BaseAcion extends ActionSupport {
private String result;
private String message;
//getters, setters
}
public class MyAction extends BaseAction {
private String myFirstField;
private String mySecondField;
public String execute() {
...
myFirstField = "someValue";
mySecondField = "someOtherValue";
...
result = SUCCESS;
message = "Some message here";
...
return result;
}
//methods, getters, setters
}
我用过struts2-json插件,动作映射是
<package name="my-package" namespace="/" extends="json-default" >
<action name="myAction" class="MyAction">
<result type="json"></result>
</action>
</package>
我收到的回复是这样的。
{
"myFirstField":"someValue",
"mySecondField":"someOtherValue"
}
我也想得到“结果”和“消息”字段作为响应。
如何在 json 响应中包含 BaseAction 字段?