参考:http://blog.csdn.net/zzjjiandan/article/details/34089313

 

https://www.cnblogs.com/Sunnor/p/6130380.html

先上图:

springmvc的ModelAndView的简单使用

 

MAVTest.java

springmvc的ModelAndView的简单使用

 1 package com.wyl;
 2 
 3 import java.util.ArrayList;
 4 import java.util.HashMap;
 5 import java.util.List;
 6 import java.util.Map;
 7 
 8 import org.springframework.stereotype.Controller;
 9 import org.springframework.web.bind.annotation.RequestMapping;
10 import org.springframework.web.servlet.ModelAndView;
11 
12 /**
13  * ModelAndView测试,
14  * 
15  * @author Wei
16  * @time 2016年12月4日 上午10:12:16
17  */
18 @Controller
19 public class MAVTest {
20 
21     public MAVTest() {
22         // TODO Auto-generated constructor stub
23     }
24 
25     @RequestMapping(value = "login")
26     public ModelAndView login() {
27         System.out.println("MAVTest.java login()....");
28         ModelAndView mav = new ModelAndView();
29         mav.setViewName("welcome");
30         mav.addObject("msg", "hello kitty");
31 
32         // List
33         List<String> list = new ArrayList<String>();
34         list.add("java");
35         list.add("c++");
36         list.add("oracle");
37         mav.addObject("bookList", list);
38 
39         // Map
40         Map<String, String> map = new HashMap<String, String>();
41         map.put("zhangsan", "北京");
42         map.put("lisi", "上海");
43         map.put("wangwu", "深圳");
44         mav.addObject("map", map);
45 
46         return mav;

相关文章:

  • 2022-12-23
  • 2021-06-21
  • 2021-08-23
  • 2021-10-14
  • 2021-09-06
  • 2022-12-23
  • 2020-01-24
猜你喜欢
  • 2021-08-29
  • 2021-07-22
  • 2023-03-09
  • 2021-10-25
  • 2021-09-14
相关资源
相似解决方案