ModelAndView的部分回顾

//@RestController @Controller //@SessionAttributes("user") //把modelandview中user attribute对象 拷贝了一份到session的共享控制当中。 public class Test01Controller { // path 和value一样 但是produces = "text/html;charset=utf-8"不能变 @RequestMapping(path = "/mv/{path}.do",produces = "text/html;charset=utf-8") public ModelAndView test(@PathVariable("path") String path){ System.out.println(path); ModelAndView mv = new ModelAndView(); Map map = new HashMap(); map.put("username","admin"); map.put("password","123456"); //一次性添加多个attribute对象 mv.addAllObjects(map); //attribute对象 request mv.addObject("user","username"); //你要跳转到那里 服务器跳转 //也可客户端跳转但是值就不能传递了 mv.setViewName("/success.jsp"); return mv; } @RequestMapping("/m.do") public String test01(@SessionAttribute("user")String user, Integer [] ids){ System.out.println("user:"+user); return "success.jsp"; } @RequestMapping(value = "/lang.do") public String introinfo(HttpServletRequest request, Model model) { Locale locale = RequestContextUtils.getLocaleResolver(request).resolveLocale(request); System.out.println(locale.getLanguage()); //DynamicDataSource.setCurrentLookupKey(locale.getLanguage()); return "success.jsp"; } }

 

版权声明:本文为chaoesha原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。
本文链接:https://www.cnblogs.com/chaoesha/p/13069002.html