struts action 返回json

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/G66565906/article/details/83862109

若需要action 返回 json格式的数据 需执行以下几个步骤

1:引入 struts2-json-plugin包至 WebContent/WEB-INF/lib下

2:设置Action所属的包为 json-default

@ParentPackage("json-defalut")

3:设置Action的 result 类型为json

@Result(name="success", type="json", params={"noCache, "true", "excludeNullProperties", "true", "root","result"})

其中 noCache : 禁用浏览器缓存

excludeNullproperties: 去除空值

root 可序列化至json的属性,若无该参数,则struts会尽可能地序列化所有的属性

猜你喜欢

转载自blog.csdn.net/G66565906/article/details/83862109