对不起,我真的不知道如何总结这个问题的题目。所以,标题可能还不清楚。
我有一个操作类,它执行一些业务逻辑。
在行动课上:
class ActionClass extends ActionSupport{
private Merchandise merchandise;// I want to transfer it to the client
//setter and getter
}
在商品类中:
class Merchandise{
private String name; // I want to transfer it
private String price; //I don't want to transfer it
private String description;//I don't want to transfer it
//setter and getter
}
现在,我需要将ActionClass中的商品属性转移到客户端。
但是,在商品属性中,我只想转移名称属性,同时抑制其他两个属性。
那么,如何抑制商品中其他两种属性(价格和描述)的转移呢?
发布于 2011-08-03 11:53:22
试一试如下:
<!-- Result fragment -->
<result type="json">
<param name="root">merchandise</param>
<param name="excludeProperties">price,description</param>
</result>
参见http://struts.apache.org/2.2.3/docs/json-plugin.html上的完整文档、其他选项和示例
发布于 2013-03-05 07:26:41
最简单的方法是在操作类中创建一个数据传输对象,该对象只包含要发送到客户端的字段,并使其成为您的根对象。
发布于 2016-11-21 07:35:05
@nmc答案是正确的,另一种您可以尝试的方法是:
<result type="json">
<param name="root">merchandise</param>
<param name="includeProperties">name</param>
</result>
或
<result type="json">
<param name="includeProperties">
merchandise.name
</param>
<param name="root">
#action
</param>
</result>
https://stackoverflow.com/questions/6922247
复制相似问题