package action;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import org.apache.struts2.json.annotations.JSON;
import com.opensymphony.xwork2.ActionSupport;
public class Jsonaction extends ActionSupport {
private static final long serialVersionUID = 1359090410097337654L;
private List<Comment> comments = new ArrayList<Comment>();
public List<Comment> getComments() {
Comment com1 = new Comment();
com1.setContent("这里是内容1");
com1.setId(1);
com1.setNickname("陈杰");
Comment com2 = new Comment();
com2.setContent("这里是内容2");
com2.setId(2);
com2.setNickname("Baiy");
comments.add(com1);
comments.add(com2);
return comments;
}
public void setComments(List<Comment> comments) {
this.comments = comments;
}
private Map<String, String> map = new HashMap<String, String>();
public Map<String, String> getMap() {
map.put("sex", "boy");
map.put("name", "baiy");
map.put("age", "1");
return map;
}
public void setMap(Map<String, String> map) {
this.map = map;
}
//没getter and setter方法的属性不会被串行化到JSON
private String title;
public String getTitle() {
return title;
}
public void setTitle(String title) {
this.title = title;
}
//!!!使用transient修饰的属性也会被串行化到JSON
private transient String content;
@JSON(serialize=false)
public String getContent() {
return content;
}
public void setContent(String content) {
this.content = content;
}
private Comment comment;
public Comment getComment() {
Comment com = new Comment();
com.setContent("Comment");
com.setId(1);
com.setNickname("Nickname");
return com;
}
public void setComment(Comment comment) {
this.comment = comment;
}
//------------------方法------------------------------
public String loadpage(){
return "success";
}
public String loadjson() {
title="这是标题";
content="我没有串行化到json";
return "success";
}
}
sturts框架下返回json数据 list map 对象
5星 · 超过95%的资源 需积分: 10 158 浏览量
2012-11-11
22:03:23
上传
评论
收藏 4.09MB RAR 举报
Baiychenvip
- 粉丝: 2
- 资源: 49
最新资源
- 2022NOC软件创意编程赛项真题python小学高年级-决赛(有解析)
- mathml转换latex需要的xsl文件
- 2022NOC软件创意编程赛项真题图形化小学高年级-决赛赛(有解析)
- gbase驱动下载gbase-connector-java-8.3.81.53驱动下载
- 2022NOC软件创意编程赛项真题图形化小学低年级-决赛赛(有解析)
- InsightFace从青铜到王者,超大规模人脸识别的优雅解法
- python后端开发spider框架详解
- 基于 STM32 与 ESP8266 的智能家居系统源码.zip
- 毕业设计:基于SSM的mysql-个性化点餐配送系统(源码 + 数据库 + 说明文档)
- 基于matlab的鱼苗计数识别(GUI界面).zip代码57
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈