1、使用ModelAndView传值(普通值和map集合)
//1、使用ModelAndView传值(普通值和map集合)@RequestMapping("/test1")public ModelAndView test1(ModelAndView m) {m.addObject("str", "你好");Map map = new HashMap();map.put("name", "坤");m.addAllObjects(map);m.setViewName("test");return m;}
2、使用Model传值
//2、使用Model传值@RequestMapping("/test2")public String test2(Model m) {m.addAttribute("str", "你好");Map map = new HashMap();map.put("name", "坏");m.addAllAttributes(map);return "test";}
2、使用普通对象(javabean对象传值)默认提示根据配置返回的jsp页面
//3、使用普通对象(javabean对象传值)默认提示根据配置返回的jsp页面@RequestMapping("/test3")public User test3() {User user = new User("123", "123");return user;}@RequestMapping("/test4")@ResponseBodypublic User test4() {User user = new User("123", "123");return user;}
4、使用redirect和forward的使用 ,跳过视图解析器 例如:redirect:/hello.jsp
//4、使用redirect和forward的使用 ,跳过视图解析器@RequestMapping("/test5")public String test5() {return "forward:/login.html";}