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

學(xué)無先后,達(dá)者為師

網(wǎng)站首頁 編程語言 正文

thymeleaf跳轉(zhuǎn)到響應(yīng)頁面(modelandview 中的view)

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

從控制器類向前端頁面跳轉(zhuǎn)時(shí),指定傳遞的頁面

modelandview 中的view

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

2.當(dāng)以forward為前綴時(shí),創(chuàng)建internalsersourceview視圖,此時(shí)不會(huì)直接被thymeleaf解析,而是將forward去掉,尋找控制器的value一樣的方法,用thymeleaf解析該方法的返回值,并請(qǐng)求轉(zhuǎn)發(fā)訪問該頁面

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

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

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

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

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

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.當(dāng)我由控制方法跳轉(zhuǎn)到頁面時(shí),不需要傳遞數(shù)據(jù),僅僅是告訴thymeleft我跳轉(zhuǎn)的頁面(僅有view)時(shí),可以在spring.xml中(視圖控制器的xml文件)中寫這句,注意

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

    

?和下面是一樣的效果

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

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

欄目分類
最近更新