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、效果

 

 

 

 

 

 

posted on 2018-03-17 14:07  手握太阳  阅读(201)  评论(0编辑  收藏  举报

导航