SpringMVC?RESTFul實(shí)戰(zhàn)案例訪問(wèn)首頁(yè)
SpringMVC RESTFul訪問(wèn)首頁(yè)實(shí)現(xiàn)
一、新建 index.html
在 webapp\WEB-INF\templates 下新建首頁(yè) index.html。
<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org">
<head>
<meta charset="UTF-8" >
<title>Title</title>
</head>
<body>
<h1>首頁(yè)</h1>
<a th:href="@{/employee}" rel="external nofollow" >查看員工信息</a>
</body>
</html>二、配置視圖控制器
在 springMVC.xml 配置文件里,配置首頁(yè)的 view-controller。另外還要開啟注解驅(qū)動(dòng)。
<?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"
xmlns:mvc="http://www.springframework.org/schema/mvc"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd
http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc.xsd">
<!-- 自動(dòng)掃描包 -->
<context:component-scan base-package="com.pingguo.rest"></context:component-scan>
<!-- 配置Thymeleaf視圖解析器 -->
<bean id="viewResolver" class="org.thymeleaf.spring5.view.ThymeleafViewResolver">
<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>
<!--
path:設(shè)置處理的請(qǐng)求地址
view-name:設(shè)置請(qǐng)求地址所對(duì)應(yīng)的視圖名稱
-->
<mvc:view-controller path="/" view-name="index"></mvc:view-controller>
<!--開啟 mvc 的注解驅(qū)動(dòng)-->
<mvc:annotation-driven />
</beans>三、Idea 部署配置
點(diǎn)擊 配置。

繼續(xù)按照順序點(diǎn)擊配置。

選擇要部署的 war 包,點(diǎn)擊確定。

最后為了方便訪問(wèn),修改下上下文(不改也可以)。

點(diǎn)擊部署,成功后自動(dòng)打開首頁(yè)。

感謝《尚硅谷》的學(xué)習(xí)資源。
以上就是SpringMVC RESTFul實(shí)戰(zhàn)案例訪問(wèn)首頁(yè)的詳細(xì)內(nèi)容,更多關(guān)于SpringMVC RESTFul訪問(wèn)首頁(yè)的資料請(qǐng)關(guān)注腳本之家其它相關(guān)文章!
- SpringMVC使用RESTful接口案例詳解
- SpringMVC?Restful風(fēng)格與中文亂碼問(wèn)題解決方案介紹
- SpringMVC通過(guò)RESTful結(jié)構(gòu)實(shí)現(xiàn)頁(yè)面數(shù)據(jù)交互
- SpringMVC?RESTFul及REST架構(gòu)風(fēng)格介紹
- SpringMVC?RESTFul實(shí)體類創(chuàng)建及環(huán)境搭建
- SpringMVC?RESTFul實(shí)現(xiàn)列表功能
- SpringMVC?RESTFul實(shí)戰(zhàn)案例刪除功能實(shí)現(xiàn)
- SpringMVC使用RESTful接口案例
相關(guān)文章
Java?Stream.reduce()用法詳細(xì)解析
Stream API提供了豐富的中間函數(shù),歸并函數(shù)和終端函數(shù),這些函數(shù)還支持并行化執(zhí)行,下面這篇文章主要給大家介紹了關(guān)于Java?Stream.reduce()用法的相關(guān)資料,需要的朋友可以參考下2022-12-12
Spring事件監(jiān)聽器ApplicationListener源碼詳解
這篇文章主要介紹了Spring事件監(jiān)聽器ApplicationListener源碼詳解,ApplicationEvent以及Listener是Spring為我們提供的一個(gè)事件監(jiān)聽、訂閱的實(shí)現(xiàn),內(nèi)部實(shí)現(xiàn)原理是觀察者設(shè)計(jì)模式,需要的朋友可以參考下2023-05-05
生產(chǎn)消費(fèi)者模式實(shí)現(xiàn)方式和線程安全問(wèn)題代碼示例
這篇文章主要介紹了生產(chǎn)消費(fèi)者模式實(shí)現(xiàn)方式和線程安全問(wèn)題代碼示例,具有一定借鑒價(jià)值,需要的朋友可以參考下2017-12-12
解決Java中的強(qiáng)制類型轉(zhuǎn)換和二進(jìn)制表示問(wèn)題
這篇文章主要介紹了解決Java中的強(qiáng)制類型轉(zhuǎn)換和二進(jìn)制表示問(wèn)題,需要的朋友可以參考下2019-05-05
springboot發(fā)送郵件功能的實(shí)現(xiàn)代碼
發(fā)郵件是一個(gè)很常見的功能,在java中實(shí)現(xiàn)需要依靠JavaMailSender這個(gè)接口,今天通過(guò)本文給大家分享springboot發(fā)送郵件功能的實(shí)現(xiàn)代碼,感興趣的朋友跟隨小編一起看看吧2021-07-07
Eclipse可視化插件WindowBuilder的安裝方法
這篇文章主要介紹了Eclipse可視化插件WindowBuilder的安裝方法,文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)學(xué)習(xí)吧2020-06-06
jvm細(xì)節(jié)探索之synchronized及實(shí)現(xiàn)問(wèn)題分析
這篇文章主要介紹了jvm細(xì)節(jié)探索之synchronized及實(shí)現(xiàn)問(wèn)題分析,涉及synchronized的字節(jié)碼表示,JVM中鎖的優(yōu)化,對(duì)象頭的介紹等相關(guān)內(nèi)容,具有一定借鑒價(jià)值,需要的朋友可以參考下。2017-11-11
Java將json字符串轉(zhuǎn)換為數(shù)組的幾種方法
在Java開發(fā)中,經(jīng)常會(huì)遇到將json字符串轉(zhuǎn)換為數(shù)組的需求,本文主要介紹了Java將json字符串轉(zhuǎn)換為數(shù)組的幾種方法,具有一定的參考價(jià)值,感興趣的可以了解一下2024-01-01
java設(shè)計(jì)模式之外觀模式學(xué)習(xí)筆記
這篇文章主要為大家詳細(xì)介紹了java設(shè)計(jì)模式之外觀模式學(xué)習(xí)筆記,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2016-10-10

