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。另外還要開啟注解驅動。
<?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:設置處理的請求地址 view-name:設置請求地址所對應的視圖名稱 --> <mvc:view-controller path="/" view-name="index"></mvc:view-controller> <!--開啟 mvc 的注解驅動--> <mvc:annotation-driven /> </beans>
三、Idea 部署配置
點擊 配置。
繼續(xù)按照順序點擊配置。
選擇要部署的 war 包,點擊確定。
最后為了方便訪問,修改下上下文(不改也可以)。
點擊部署,成功后自動打開首頁。
感謝《尚硅谷》的學習資源。
以上就是SpringMVC RESTFul實戰(zhàn)案例訪問首頁的詳細內容,更多關于SpringMVC RESTFul訪問首頁的資料請關注腳本之家其它相關文章!
相關文章
Spring事件監(jiān)聽器ApplicationListener源碼詳解
這篇文章主要介紹了Spring事件監(jiān)聽器ApplicationListener源碼詳解,ApplicationEvent以及Listener是Spring為我們提供的一個事件監(jiān)聽、訂閱的實現(xiàn),內部實現(xiàn)原理是觀察者設計模式,需要的朋友可以參考下2023-05-05springboot發(fā)送郵件功能的實現(xiàn)代碼
發(fā)郵件是一個很常見的功能,在java中實現(xiàn)需要依靠JavaMailSender這個接口,今天通過本文給大家分享springboot發(fā)送郵件功能的實現(xiàn)代碼,感興趣的朋友跟隨小編一起看看吧2021-07-07Eclipse可視化插件WindowBuilder的安裝方法
這篇文章主要介紹了Eclipse可視化插件WindowBuilder的安裝方法,文中通過示例代碼介紹的非常詳細,對大家的學習或者工作具有一定的參考學習價值,需要的朋友們下面隨著小編來一起學習學習吧2020-06-06jvm細節(jié)探索之synchronized及實現(xiàn)問題分析
這篇文章主要介紹了jvm細節(jié)探索之synchronized及實現(xiàn)問題分析,涉及synchronized的字節(jié)碼表示,JVM中鎖的優(yōu)化,對象頭的介紹等相關內容,具有一定借鑒價值,需要的朋友可以參考下。2017-11-11