步骤一:编写Action
public class ClientAction extends BaseAction {
private Map<String,Object> resultMap = new TreeMap<String, Object>();
public Map<String, Object> getResultMap() {
return resultMap;
}
public void setResultMap(Map<String, Object> resultMap) {
this.resultMap = resultMap;
}
}
步骤二:配置Action
<package name="json-protected-default" extends="vOrderGwMan">
<result-types>
<result-type name="json" class="org.apache.struts2.json.JSONResult"/>
</result-types>
<interceptors>
<interceptor name="json" class="org.apache.struts2.json.JSONInterceptor"/>
</interceptors>
<!--全局异常输出-->
<global-results>
<result name="exception" type="plainText">/WEB-INF/vm/json_error.txt</result>
<result name="error" type="plainText">/WEB-INF/vm/json_error.txt</result>
</global-results>
<global-exception-mappings>
<exception-mapping exception="java.lang.Exception" result="exception"/>
</global-exception-mappings>
</package>
<package name="client" namespace="/api" extends="json-protected-default">
<!--公共请求Action-->
<action name="client" class="com.jd.vordergw.server.web.action.ClientAction">
<result type="json">
<param name="ignoreHierarchy">true</param>
<param name="excludeNullProperties">false</param>
<param name="root">resultMap</param>
</result>
</action>
</package>
说明:这边的resultMap和Action类里面的属性是一致的