在controller中写 @RequestMapping(中的params="json")
@RequestMapping(value = "/{username}", params = "json") @ResponseBody public User showJson(@PathVariable String username, Model model) { return users.get(username); }