我用了Struts2、jsonplugin。
struts.xml中部分代码: <package name="example" extends="json-default">
<action name="JSONExample" class="com.test.UserAction">
<result type="json">
<param name="includeProperties">
name,age
</param>
</result>
</action>
</package>
运行时,还是把UserAction中所有的属性都序列化成json字符串了,为什么会这样。我想要的json字符串中只包含name,age两个属性。看似我配置的includeProperties根本没起作用!如果换成excludeProperties后,得到的json中没有name和age两个属性,这是正常的。为什么includeProperties不起作用,求助!
struts.xml中部分代码: <package name="example" extends="json-default">
<action name="JSONExample" class="com.test.UserAction">
<result type="json">
<param name="includeProperties">
name,age
</param>
</result>
</action>
</package>
运行时,还是把UserAction中所有的属性都序列化成json字符串了,为什么会这样。我想要的json字符串中只包含name,age两个属性。看似我配置的includeProperties根本没起作用!如果换成excludeProperties后,得到的json中没有name和age两个属性,这是正常的。为什么includeProperties不起作用,求助!
从0.28版本才开始支持includeProperties,希望朋友们注意这细节,奇怪的是我的控制台没打印警告信息!
<package name="example" extends="json-default">
<action name="JSONExample" class="com.test.UserAction">
<result type="json">
<param name="ignoreHierarchy">false</param>
<param name="includeProperties">
name,age
</param>
</result>
</action>
</package>