如何从spring MVC返回JSON对象列表?

时间:2012-02-15 16:55:57

标签: dojox.grid

如何返回json对象的列表,如{“items”:“[”{“”:“”},{“”:“”},...“]”}形成Spring MVC3.0?请帮助一下......

1 个答案:

答案 0 :(得分:0)

@RequestMapping(value="/list", method=RequestMethod.GET)//, headers=ACCEPT_JSON)
@ResponseBody
public List<User> userList() {
    LOG.info("get list of Users");

    List<User> users = new ArrayList<User>();
    users.add(new User("user1", "pass1", "name1", Boolean.TRUE));
    users.add(new User("user2", "pass2", "name2", Boolean.TRUE));
    users.add(new User("user3", "pass3", "name3", Boolean.TRUE));

    return users;
}