spring mvc

来源:互联网 发布:seo编辑岗位职责 编辑:程序博客网 时间:2024/06/16 08:52

1、在两个controller或者页面间跳转,page1可使用ModelAndView的redirect,或者forward方法,也可以直接使用redirect方法;

2、controller间传参时,可使用ModelAndView的addObject方法,跳转到page2的时候,springmvc会将参数之间拼接在url上,key/value方式;

3、controller间参数,为隐藏参数,可使用RedirectAttributes类,该类的addAttribute方法加参数和2的效果一致,addFlashAttribute方法会将参数临时加在session中,在page2页面上可使用el表达式直接获取,页面跳转成功后session会移除;

      在page2的controller中,获取传递的参数有两种方式 :

3.1、使用

RequestContextUtils.getInputFlashMap(HttpServletRequest)
,拿到一个map,map类型为Map<String,?>;

3.2、直接使用spring mvc的Model:

Map map = model.asMap();

方法;


参考:http://blog.csdn.net/paincupid/article/details/52263817