关于springmvc 页面跳转问题


一共有普通跳转,带参数跳转,装发,重定向 这4种

@Controller
@RequestMapping("/test")
public class HelloAction {

	@RequestMapping("/hello")
	public String zhHello(){
		//普通转发,直接到页面,简单快捷
		return "hello";
	}
	@RequestMapping("/sshello")
	public String sshello(Model m){
		//以model为容器,带参数到指定页面
		m.addAttribute("ss", "zhangsan");
		
		return "ss";
	}
	
	@RequestMapping("/fora")
	public String  fora(Model m){
               //带参数转发,

		m.addAttribute("ww", "王");
		return "forward:../WEB-INF/view/ss.jsp";
	}
	/*
	 * 重定向:页面
	 */
	@RequestMapping("/re")
	public String redi(Model m){
		return "redirect:../WEB-INF/view/ss.jsp";
	}
	/*
	 * 从重定向: 方法
	 */
	@RequestMapping("/rew")
	public String  rew(Model m){
		m.addAttribute("wang", "王小二");
		return "redirect:hello.action";
	}
	
}


猜你喜欢

转载自blog.csdn.net/qq_39387571/article/details/78930059
今日推荐