一、没有视图解析器的情况(忽略,不用)

视图解析器

    <!-- 视图解析器 -->
    <bean class="org.springframework.web.servlet.view.InternalResourceViewResolver"
          id="internalResourceViewResolver">
        <!-- 前缀 -->
        <property name="prefix" value="/WEB-INF/jsp/" />
        <!-- 后缀 -->
        <property name="suffix" value=".jsp" />
    </bean>
    @GetMapping("/add/{a}/{b}")
    public String showHi(@PathVariable int a, @PathVariable int b, Model model){
        String result = "结果是:" + (a + b);
        model.addAttribute("msg", result);
        // return "/WEB-INF/jsp/hi.jsp";  转发
        // return "forward:/WEB-INF/jsp/hi.jsp";  转发
        return "redirect:/WEB-INF/jsp/index.jsp";  重定向 
    }

转发、重定向

二、有视图解析器

1、默认是转发

2、重定向

    @GetMapping("/add/{a}/{b}")
    public String showHi(@PathVariable int a, @PathVariable int b, Model model){
        String result = "结果是:" + (a + b);
        model.addAttribute("msg", result);
        return "redirect:/index.jsp";
    }

 

相关文章:

  • 2021-04-22
  • 2021-10-17
  • 2021-12-05
  • 2022-01-09
  • 2021-07-17
  • 2022-01-12
猜你喜欢
  • 2021-10-17
  • 2021-10-17
  • 2021-11-21
相关资源
相似解决方案