当前位置: 代码迷 >> 综合 >> Springmvc后台数据传前台
  详细解决方案

Springmvc后台数据传前台

热度:39   发布时间:2024-01-22 05:08:36.0

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";}

  相关解决方案