SpringMVC?RESTFul實戰(zhàn)案例訪問首頁
SpringMVC RESTFul訪問首頁實現(xiàn)
一、新建 index.html
在 webapp\WEB-INF\templates 下新建首頁 index.html。
<!DOCTYPE html> <html lang="en" xmlns:th="http://www.thymeleaf.org"> <head> <meta charset="UTF-8" > <title>Title</title> </head> <body> <h1>首頁</h1> <a th:href="@{/employee}" rel="external nofollow" >查看員工信息</a> </body> </html>
二、配置視圖控制器
在 springMVC.xml 配置文件里,配置首頁的 view-controller。另外還要開啟注解驅(qū)動。
<?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"> <!-- 自動掃描包 --> <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è)置處理的請求地址 view-name:設(shè)置請求地址所對應(yīng)的視圖名稱 --> <mvc:view-controller path="/" view-name="index"></mvc:view-controller> <!--開啟 mvc 的注解驅(qū)動--> <mvc:annotation-driven /> </beans>
三、Idea 部署配置
點擊 配置。
繼續(xù)按照順序點擊配置。
選擇要部署的 war 包,點擊確定。
最后為了方便訪問,修改下上下文(不改也可以)。
點擊部署,成功后自動打開首頁。
感謝《尚硅谷》的學(xué)習(xí)資源。
以上就是SpringMVC RESTFul實戰(zhàn)案例訪問首頁的詳細內(nèi)容,更多關(guān)于SpringMVC RESTFul訪問首頁的資料請關(guān)注腳本之家其它相關(guān)文章!
相關(guān)文章
Spring事件監(jiān)聽器ApplicationListener源碼詳解
這篇文章主要介紹了Spring事件監(jiān)聽器ApplicationListener源碼詳解,ApplicationEvent以及Listener是Spring為我們提供的一個事件監(jiān)聽、訂閱的實現(xiàn),內(nèi)部實現(xiàn)原理是觀察者設(shè)計模式,需要的朋友可以參考下2023-05-05生產(chǎn)消費者模式實現(xiàn)方式和線程安全問題代碼示例
這篇文章主要介紹了生產(chǎn)消費者模式實現(xiàn)方式和線程安全問題代碼示例,具有一定借鑒價值,需要的朋友可以參考下2017-12-12springboot發(fā)送郵件功能的實現(xiàn)代碼
發(fā)郵件是一個很常見的功能,在java中實現(xiàn)需要依靠JavaMailSender這個接口,今天通過本文給大家分享springboot發(fā)送郵件功能的實現(xiàn)代碼,感興趣的朋友跟隨小編一起看看吧2021-07-07Eclipse可視化插件WindowBuilder的安裝方法
這篇文章主要介紹了Eclipse可視化插件WindowBuilder的安裝方法,文中通過示例代碼介紹的非常詳細,對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧2020-06-06jvm細節(jié)探索之synchronized及實現(xiàn)問題分析
這篇文章主要介紹了jvm細節(jié)探索之synchronized及實現(xiàn)問題分析,涉及synchronized的字節(jié)碼表示,JVM中鎖的優(yōu)化,對象頭的介紹等相關(guān)內(nèi)容,具有一定借鑒價值,需要的朋友可以參考下。2017-11-11Java將json字符串轉(zhuǎn)換為數(shù)組的幾種方法
在Java開發(fā)中,經(jīng)常會遇到將json字符串轉(zhuǎn)換為數(shù)組的需求,本文主要介紹了Java將json字符串轉(zhuǎn)換為數(shù)組的幾種方法,具有一定的參考價值,感興趣的可以了解一下2024-01-01java設(shè)計模式之外觀模式學(xué)習(xí)筆記
這篇文章主要為大家詳細介紹了java設(shè)計模式之外觀模式學(xué)習(xí)筆記,具有一定的參考價值,感興趣的小伙伴們可以參考一下2016-10-10