How to return json data selectively in a struts2 action class(如何在 struts2 动作类中选择性地返回 json 数据)
问题描述
我在一个动作类中有几个带有 getter 和 setter 方法的属性.
I have several properties with getter and setter method in one action class.
这些属性不执行相同的任务.实际上,它们响应不同的业务服务请求,或者它们与不同的操作相关.
Those properties do not perform the same task. Actually, they respond to different business-service requests, or they are related to different actions.
而我的问题是这样的:
我需要过滤掉数据并仅返回属性集中的部分属性,因为在单个请求(操作)中并非所有属性都是必需的.
I need to filter out the data and return only part of the properties within the property set because not all properties are necessary in a single request(action).
PS:实际上,我可能已经将这些动作或业务逻辑分成几个类,而不是把它们放在一个动作类中.但是,我认为它们都共享相似的 DAO 和服务,因此我将它们放在一起以防止冗余 IOC.
PS:Actually, I might have separated those actions or business logic into several classes instead of putting them into one action class. However, I think they all share the similar DAOs and services so I put them together in order to prevent redundant IOCs.
推荐答案
Struts2-JSON 插件 允许您排除空属性
<result type="json">
<param name="excludeNullProperties">true</param>
</result>
或排除某些参数被序列化
or exclude certain parameters from being serialized
<result type="json">
<param name="excludeProperties">
login.password,
studentList.*.sin
</param>
</result>
有关详细信息,请参阅文档
这篇关于如何在 struts2 动作类中选择性地返回 json 数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:如何在 struts2 动作类中选择性地返回 json 数据


基础教程推荐
- 存储 20 位数字的数据类型 2022-01-01
- 问题http://apache.org/xml/features/xinclude测试日志4j 2 2022-01-01
- 无法复制:“比较方法违反了它的一般约定!" 2022-01-01
- 使用堆栈算法进行括号/括号匹配 2022-01-01
- REST Web 服务返回 415 - 不支持的媒体类型 2022-01-01
- RabbitMQ:消息保持“未确认"; 2022-01-01
- 如何对 Java Hashmap 中的值求和 2022-01-01
- 修改 void 函数的输入参数,然后读取 2022-01-01
- Spring AOP错误无法懒惰地为此建议构建thisJoinPoin 2022-09-13
- Struts2 URL 无法访问 2022-01-01