版權聲明:本文爲博主原創文章,未經博主容許不得轉載。 https://blog.csdn.net/Geek_Alex/article/details/78845532正則表達式
<dependency> <groupId>org.apache.struts</groupId> <artifactId>struts2-json-plugin</artifactId> <version>${struts2.version}</version> </dependency> <dependency> <groupId>org.apache.struts</groupId> <artifactId>struts2-convention-plugin</artifactId> <version>${struts2.version}</version> </dependency>
1.使用註解@ParentPackage("json-default")
註解Action類markdown
2.設置result的type爲jsonpost
@Result(name = "error", type = "json")spa
a.默認狀況下以get方法會被序列化,.net
b.可以使用註解 @JSON(serialize=false)關閉某個get方法的序列化。code
c.若是在屬性get方法上面加 @JSON(name=」newName」),則返回的json數據中key是指定的新名稱。orm
d. @JSON(format ="yyyy-MM-dd'T'HH:mm:ss」)設置用於格式化json數據中的日期。xml
e. @JSON(deserialize=true)設置是否反序列化該屬性。
使用方法::
@Action(value="xxxx",results={ @Result(name=「xxx」type="json",params={"root","要返回的數據名稱"})})
使用方法:: @Action(value="xxxx",results={ @Result(name=「xxx」type="json",params={「excludeNullProperties","true"})})
使用方法:: @Action(value="xxxx",results={ @Result(name=「xxx」type="json",params={"ignoreHierarchy","true"})})
使用方法:: @Action(value="xxxx",results={ @Result(name=「xxx」type="json",params={"includeProperties","msg,user\\.username,list\\[1\\]\\.password,map.*","prefix","true"})})
使用方法:@Action(value="xxxx",results={ @Result(name=「xxx」type="json",
params={"excludeProperties","msg,user\\.username,list\\[1\\]\\.password,map.*","prefix","true")})