@RequestMapping("/testModelAndView") public ModelAndView testModelAndView() { //1、创建ModelAndView对象 ModelAndView mv = new ModelAndView(); System.out.println("testModelAndView方法执行了..."); User user = new User(); user.setUsername("小凤"); user.setPassword("456"); user.setAge(30); //把user对象存储到mv对象中,也会把user对象存入到request对象。 mv.addObject("user",user); //跳转到哪个页面 mv.setViewName("success"); return mv; }