原文地址:https://zhidao.baidu.com/question/361314391898120412.html
一个Struts 2的struts.xml中配置json类型result的带完整参数注释的例子:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
|
... < package name = "json" extends = "json-default" namespace = "/test" > < action name = "testByAction" class = "cn.ysh.studio.struts2.json.demo.action.UserAction" method = "testByAction" > < result type = "json" > <!-- 这里指定将被Struts2序列化的属性,该属性在action中必须有对应的getter方法 --> <!-- 默认将会序列所有有返回值的getter方法的值,而无论该方法是否有对应属性 --> < param name = "root" >dataMap</ param > <!-- 指定是否序列化空的属性 --> < param name = "excludeNullProperties" >true</ param > <!-- 这里指定将序列化dataMap中的那些属性 --> < param name = "includeProperties" > user.* </ param > <!-- 指定内容类型,默认为application/json,IE浏览器会提示下载 --> < param name = "contentType" >text/html</ param > <!-- 这里指定将要从dataMap中排除那些属性,这些排除的属性将不被序列化,一半不与上边的参数配置同时出现 --> < param name = "excludeProperties" > SUCCESS </ param > </ result > </ action > </ package > |
可以看到,这些param参数是和<result type="json">也就是result的类型有关的,不同的result type其参数的含义可能不一样。
json类型result type需要配置的这些参数,主要是用于返回json类型值时控制其struts 2 Action对应返回哪些属性的。