Spring MVC-从零开始-view-forward、redirect
1、forward或redirect后,不再走viewResolver过程,直接重新从控制器开始
2、代码
package com.jt; import org.springframework.stereotype.Controller; import org.springframework.ui.ModelMap; import org.springframework.web.bind.annotation.RequestMapping; @Controller @RequestMapping(value="view") public class TestModelAndView { @RequestMapping(value="getInfoHander1") public String getInfoHander1(ModelMap map){ map.addAttribute("name", "fy"); map.addAttribute("gender","woman"); return "forward:viewPersonInfo"; } @RequestMapping(value="getInfoHander2") public String getInfoHander2(ModelMap map){ map.addAttribute("name", "fy"); map.addAttribute("gender","woman"); return "redirect:viewPersonInfo"; } @RequestMapping(value="getInfoHander3") public String getInfoHander3(ModelMap map){ map.addAttribute("name", "fy"); map.addAttribute("gender","woman"); return "redirect:/viewPersonInfo"; } }
3、效果