栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 面试经验 > 面试问答

Struts 2中的Json插件出现问题

面试问答 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

Struts 2中的Json插件出现问题

是的,有可能,该解决方案需要使用包含/排除参数。

以下是一个示例。

方法getJson1和getJson2显示includeParameters,而getJson3显示excludeParameters。

注意:尽管本示例使用字符串作为include / exclude参数的参数,但该字符串被解释为正则表达式。因此,我可以将action3上的“
string1,string2”替换为“ string *”。

有关更多信息,请参见:https
:
//cwiki.apache.org/confluence/display/WW/JSON%20Plugin

package struts2;import com.opensymphony.xwork2.ActionSupport;import org.apache.struts2.convention.annotation.Action;import org.apache.struts2.convention.annotation.ParentPackage;import org.apache.struts2.convention.annotation.Result;@ParentPackage("json-default")public class Test2 extends ActionSupport {    private String string1 = "One";    private String string2 = "Two";    private String other = "Other";    public String getString1() {        return this.string1;    }    public String getString2() {        return this.string2;    }    public String getOther() {        return this.other;    }    @Action(value="/getJson1", results = {        @Result(type = "json", params = { "includeProperties", "string1"        })})    public String action1() {        return ActionSupport.SUCCESS;    }    @Action(value="/getJson2", results = {        @Result(type = "json", params = { "includeProperties", "string2"        })})    public String action2() {        return ActionSupport.SUCCESS;    }    @Action(value="/getJson3", results = {        @Result(type = "json", params = { "excludeProperties", "string1, string2"        })})    public String action3() {        return ActionSupport.SUCCESS;    }}

… / getJson1 返回{“ string1”:“一个”}

… / getJson2 返回{“ string2”:“ Two”}

… / getJson3 返回{“ other”:“ Other”}



转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/413402.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号