复杂一些的spring json示例
在在spring web项目中使用json视图中,写了个最简单的json示例。现在输出的内容复杂一些,比如类图关系如下:
代码见:
http://easymorse.googlecode.com/svn/tags/spring.json.demo-0.2
返回值如下:
{"page":{"results":[{"authors":[{"name":"张三","id":"1"},{"name":"李四","id":"2"}],"name":"五百年来谁著史","id":"1"}],"pageNo":2}}
主要复杂了的部分是:
@Controller
public class DemoService {
@RequestMapping("/a.json")
public String doService(ModelMap modelMap) {
Pagination pagination = new Pagination();
pagination.setPageNo(2);
pagination.setResults(new ArrayList<Object>());
Book book = new Book();
book.setId("1");
book.setName("五百年来谁著史");
book.setAuthors(new ArrayList<Author>());
pagination.getResults().add(book);
Author author = new Author();
author.setId("1");
author.setName("张三");
book.getAuthors().add(author);
author = new Author();
author.setId("2");
author.setName("李四");
book.getAuthors().add(author);
modelMap.put("page", pagination);
return "list";
}
这篇文章上的评论的 RSS feed TrackBack URI