欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

簡單的一次springMVC路由跳轉(zhuǎn)實(shí)現(xiàn)

 更新時間:2022年04月14日 15:49:36   作者:上升的蝸牛  
本文主要介紹了springMVC路由跳轉(zhuǎn)實(shí)現(xiàn),文中通過示例代碼介紹的非常詳細(xì),對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧

實(shí)現(xiàn)目標(biāo):使用springMVC前端控制器,跳轉(zhuǎn)到WEB-INF的templates下面的前端頁面

圖示

在這里插入圖片描述

1.目錄結(jié)構(gòu)

在這里插入圖片描述

2.創(chuàng)建一個maven的webapp項目,創(chuàng)建好之后記得把index.jsp文件刪除,否i則會首先跳到這個文件,我們要用前端控制器轉(zhuǎn)發(fā)所有請求(如果有大佬知道怎么讓他存在,又不影響,希望可以學(xué)習(xí)一下)

在這里插入圖片描述

3.在xml里面,配置springMVC前端控制器,

<!DOCTYPE web-app PUBLIC
 "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN"
 "http://java.sun.com/dtd/web-app_2_3.dtd" >

<web-app>
  <display-name>Archetype Created Web Application</display-name>

<!--  配置springMVC的前端控制器,對瀏覽器發(fā)送的請求進(jìn)行統(tǒng)一處理-->
  <servlet>
    <servlet-name>springMVC</servlet-name>
    <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
  <!--  配置SpringMVC配置文件的位置和名稱-->
    <init-param>
      <param-name>contextConfigLocation</param-name>
      <param-value>classpath:springMVC.xml</param-value>
    </init-param>
    <!--將前端控制器DispatcherServlet的初始化時間提前到服務(wù)器啟動時-->
    <load-on-startup>1</load-on-startup>
  </servlet>
  <servlet-mapping>
    <servlet-name>springMVC</servlet-name>
    <!--匹配除了.jsp請求路徑的請求-->
    <url-pattern>/</url-pattern>
  </servlet-mapping>
</web-app>

4.創(chuàng)建并配置springMVC.xml,記得配置一下context(開啟掃描需要)

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
       xmlns:context="http://www.springframework.org/schema/context"
       xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd">
<!--    掃描組件-->
    <context:component-scan base-package="com.atguigu.mvc.controller"></context:component-scan>
    <!-- 配置Thymeleaf視圖解析器 -->
    <bean id="viewResolver" class="org.thymeleaf.spring5.view.ThymeleafViewResolver">
        <!--設(shè)置視圖解析器優(yōu)先級,可以設(shè)置多個-->
        <property name="order" value="1"/>
        <property name="characterEncoding" value="UTF-8"/>
        <property name="templateEngine">
            <bean class="org.thymeleaf.spring5.SpringTemplateEngine">
                <property name="templateResolver">
                    <bean class="org.thymeleaf.spring5.templateresolver.SpringResourceTemplateResolver">

                        <!-- 視圖前綴 -->
                        <property name="prefix" value="/WEB-INF/templates/"/>

                        <!-- 視圖后綴 -->
                        <property name="suffix" value=".html"/>
                        <property name="templateMode" value="HTML5"/>
                        <property name="characterEncoding" value="UTF-8" />
                    </bean>
                </property>
            </bean>
        </property>
    </bean>
</beans>

5.匹配路徑

@Controller
public class HelloController {
    //"/" -->/web-inf/templates/index.html
    //RequestMapping請求映射
    //value可不寫
    @RequestMapping(value="/")
    public String tindex(){
        //返回視圖名稱,因?yàn)槲覀冊谝晥D解析器里面,配置了后綴,所以這里不用寫了
        return "index";
    }

    @RequestMapping(value="/target")
    public String toTarget(){
        return "target";
    }
}

index.html

<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="UTF-8">
    <title>/</title>
</head>
<body>
<!--/瀏覽器從哪個localhost:8080開始-->
<!--th:被thymeleaf解析,可從localhost:8080:項目名字開始-->
<!--@{}檢測到絕對路徑,自動添加上下文路徑-->
<a th:href="@{/target}" rel="external nofollow" >訪問目標(biāo)</a>
ahhahahahah
</body>
</html>

target.html

<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
</head>
<body>
HELLOWORLD
</body>
</html>

到此這篇關(guān)于簡單的一次springMVC路由跳轉(zhuǎn)實(shí)現(xiàn)的文章就介紹到這了,更多相關(guān)springMVC 路由跳轉(zhuǎn)內(nèi)容請搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!

相關(guān)文章

  • Fluent Mybatis 批量更新的使用

    Fluent Mybatis 批量更新的使用

    本文主要介紹了Fluent Mybatis 批量更新的使用,文中通過示例代碼介紹的非常詳細(xì),具有一定的參考價值,感興趣的小伙伴們可以參考一下
    2021-08-08
  • ConstraintValidator類如何實(shí)現(xiàn)自定義注解校驗(yàn)前端傳參

    ConstraintValidator類如何實(shí)現(xiàn)自定義注解校驗(yàn)前端傳參

    這篇文章主要介紹了ConstraintValidator類實(shí)現(xiàn)自定義注解校驗(yàn)前端傳參的操作,具有很好的參考價值,希望對大家有所幫助。如有錯誤或未考慮完全的地方,望不吝賜教
    2021-06-06
  • 解決Springboot項目打包后的頁面丟失問題(thymeleaf報錯)

    解決Springboot項目打包后的頁面丟失問題(thymeleaf報錯)

    這篇文章主要介紹了解決Springboot項目打包后的頁面丟失問題(thymeleaf報錯),具有很好的參考價值,希望對大家有所幫助。如有錯誤或未考慮完全的地方,望不吝賜教
    2021-11-11
  • spring boot + mybatis實(shí)現(xiàn)動態(tài)切換數(shù)據(jù)源實(shí)例代碼

    spring boot + mybatis實(shí)現(xiàn)動態(tài)切換數(shù)據(jù)源實(shí)例代碼

    這篇文章主要給大家介紹了關(guān)于spring boot + mybatis實(shí)現(xiàn)動態(tài)切換數(shù)據(jù)源的相關(guān)資料,文中通過示例代碼介紹的非常詳細(xì),對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧
    2018-10-10
  • IntelliJ IDEA 2020.3.3現(xiàn)已發(fā)布!新增“受信任項目”功能

    IntelliJ IDEA 2020.3.3現(xiàn)已發(fā)布!新增“受信任項目”功能

    這篇文章主要介紹了IntelliJ IDEA 2020.3.3現(xiàn)已發(fā)布!新增“受信任項目”功能,本文給大家分享了idea2020.3.3激活碼的詳細(xì)破解教程,每種方法都很好用,使用idea2020.3以下所有版本,需要的朋友可以參考下
    2021-03-03
  • JVM執(zhí)行引擎和垃圾回收要點(diǎn)總結(jié)

    JVM執(zhí)行引擎和垃圾回收要點(diǎn)總結(jié)

    不論是在問題現(xiàn)場還是跳槽面試,我們面對JVM性能問題,依舊會束手無辭,它需要你對Java虛擬機(jī)的實(shí)現(xiàn)和優(yōu)化,有極為深刻的理解。所以我在這里整理了一下 JVM的知識點(diǎn)。今天說說虛擬機(jī)執(zhí)行引擎和垃圾回收,都是十足的干貨,請各位看官耐心批閱!
    2021-06-06
  • SpringBoot切面攔截@PathVariable參數(shù)及拋出異常的全局處理方式

    SpringBoot切面攔截@PathVariable參數(shù)及拋出異常的全局處理方式

    這篇文章主要介紹了SpringBoot切面攔截@PathVariable參數(shù)及拋出異常的全局處理方式,具有很好的參考價值,希望對大家有所幫助。如有錯誤或未考慮完全的地方,望不吝賜教
    2021-08-08
  • Java 線程池_動力節(jié)點(diǎn)Java學(xué)院整理

    Java 線程池_動力節(jié)點(diǎn)Java學(xué)院整理

    系統(tǒng)啟動一個新線程的成本是比較高的,因?yàn)樗婕暗脚c操作系統(tǒng)的交互。在這種情況下,使用線程池可以很好的提供性能,尤其是當(dāng)程序中需要創(chuàng)建大量生存期很短暫的線程時,更應(yīng)該考慮使用線程池
    2017-05-05
  • MyBatis中的自定義TypeHandler詳解

    MyBatis中的自定義TypeHandler詳解

    這篇文章主要介紹了MyBatis中的自定義TypeHandler詳解,定義的?typeHandler?泛型為?String,顯然我們要把數(shù)據(jù)庫的數(shù)據(jù)類型轉(zhuǎn)化為?String?型,然后實(shí)現(xiàn)設(shè)置參數(shù)和獲取結(jié)果集的方法,需要的朋友可以參考下
    2023-07-07
  • java 定時器線程池(ScheduledThreadPoolExecutor)的實(shí)現(xiàn)

    java 定時器線程池(ScheduledThreadPoolExecutor)的實(shí)現(xiàn)

    這篇文章主要介紹了java 定時器線程池(ScheduledThreadPoolExecutor),文中通過示例代碼介紹的非常詳細(xì),對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧
    2020-06-06

最新評論