版权声明:本文为博主原创文章,未经博主容许不得转载。 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")})