本文介绍了如何在struts2动作类中有选择地返回json数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述 29岁程序员,3月因学历无情被辞! 我在一个动作类中有几个带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数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 上岸,阿里云!
06-25 01:45
查看更多