@RequestMapping("/addUser4") @ResponseBody public String addUser4(User user) { log.info("userName is:" + user.getUserName()); log.info("password is:" + user.getPassword()); return user.getUserName(); }
@RequestMapping("/addUser6") public void addUser6(User user, PrintWriter out) { log.info("userName is:" + user.getUserName()); log.info("password is:" + user.getPassword()); String json = null; /** 使用Jackson */ ObjectMapper map = new ObjectMapper(); try { json = map.writeValueAsString(user); } catch (JsonGenerationException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (JsonMappingException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } log.info("使用Jackson:" + json); /** 使用fastjson */ json = JSON.toJSONString(user); log.info("使用fastjson:" + json); out.write(json); }
@RequestMapping("/addUser3") public String addUser3(User user, Model model) { log.info("userName is:" + user.getUserName()); log.info("password is:" + user.getPassword()); model.addAttribute(user); return "/user/success2"; }