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

 

Spring MVC-从零开始-view-forward、redirect

 

 

 

 Spring MVC-从零开始-view-forward、redirect

Spring MVC-从零开始-view-forward、redirect

 

相关文章:

  • 2021-07-06
  • 2021-09-06
  • 2021-06-06
  • 2018-05-17
  • 2021-12-04
  • 2021-09-29
  • 2021-05-20
  • 2022-12-23
猜你喜欢
  • 2021-10-16
  • 2021-07-19
  • 2021-06-27
  • 2022-12-23
  • 2021-07-27
  • 2021-08-25
相关资源
相似解决方案