日本免费高清视频-国产福利视频导航-黄色在线播放国产-天天操天天操天天操天天操|www.shdianci.com

學無先后,達者為師

網站首頁 編程語言 正文

thymeleaf跳轉到響應頁面(modelandview 中的view)

作者:仰望星空的快樂 更新時間: 2022-05-10 編程語言

從控制器類向前端頁面跳轉時,指定傳遞的頁面

modelandview 中的view

1.當返回的就是我要顯示的頁面名時,使用thymeleaf解析器(thymeleaf設置的視圖解析器)解析出文件地址,轉發方式跳轉到該頁面

2.當以forward為前綴時,創建internalsersourceview視圖,此時不會直接被thymeleaf解析,而是將forward去掉,尋找控制器的value一樣的方法,用thymeleaf解析該方法的返回值,并請求轉發訪問該頁面

?@RequestMapping("/forward_thymeleaf")
? ? public String forwrad_thyleaf()
? ? {
? ? ? ? return "forward:/test_thymeleaf";
? ? }

會尋找有?@RequestMapping("/test_thymeleaf")的控制方法,用thymeleaf解析該方法的返回值,得出文件的路徑,并請求轉發跳轉至該頁面

2.當以redirect為前綴時,創建internalsersourceview視圖,此時不會直接被thymeleaf解析,而是將forward去掉,尋找控制器的value一樣的方法,用thymeleaf解析該方法的返回值,并重定向訪問該頁面

?@RequestMapping("/forward_thymeleaf")
? ? public String forwrad_thyleaf()
? ? {
? ? ? ? return "forward:/test_thymeleaf";
? ? }

會尋找有?@RequestMapping("/test_thymeleaf")的控制方法,用thymeleaf解析該方法的返回值,得出文件的路徑,并請求重定向至該頁面-

package org.hxut.rj1192.zyk;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

@Controller
public class ViewController {
    @RequestMapping("/test_thymeleaf")
    public String thyleaf()
    {
        return "test_restful";
    }
    @RequestMapping("/")
    public String thyleafsucess()
    {
        return "index";
    }
    @RequestMapping("/forward_thymeleaf")
    public String forwrad_thyleaf()
    {
        return "forward:/test_thymeleaf";
    }
    @RequestMapping("/redirect_thymeleaf")
    public String redirect_thyleaf()
    {
        return "redirect:/test_thymeleaf";
    }
}

4.當我由控制方法跳轉到頁面時,不需要傳遞數據,僅僅是告訴thymeleft我跳轉的頁面(僅有view)時,可以在spring.xml中(視圖控制器的xml文件)中寫這句,注意

一定要寫,否則其他@requestparam注解會全部失效
    

    

?和下面是一樣的效果

 @RequestMapping("/")
public String thyleafsucess()
{
   return "index";
}

原文鏈接:https://blog.csdn.net/sharesb/article/details/124381312

欄目分類
最近更新