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)案例訪問首頁的詳細內(nèi)容,更多關于SpringMVC RESTFul訪問首頁的資料請關注腳本之家其它相關文章!
相關文章
spring cloud 之 客戶端負載均衡Ribbon深入理解
下面小編就為大家?guī)硪黄猻pring cloud 之 客戶端負載均衡Ribbon深入理解。小編覺得挺不錯的,現(xiàn)在就分享給大家,也給大家做個參考。一起跟隨小編過來看看吧2017-06-06
解決BeanUtils.copyProperties無法成功封裝的問題
這篇文章主要介紹了解決BeanUtils.copyProperties無法成功封裝的問題,具有很好的參考價值,希望對大家有所幫助。如有錯誤或未考慮完全的地方,望不吝賜教2021-06-06
Mybatis詳解動態(tài)SQL以及單表多表查詢的應用
MyBatis的動態(tài)SQL是基于OGNL表達式的,它可以幫助我們方便的在SQL語句中實現(xiàn)某些邏輯,下面這篇文章主要給大家介紹了關于Mybatis超級強大的動態(tài)SQL語句的相關資料,需要的朋友可以參考下2022-06-06
SpringBoot整合數(shù)據(jù)庫訪問層的實戰(zhàn)
本文主要介紹了SpringBoot整合數(shù)據(jù)庫訪問層的實戰(zhàn),主要包含JdbcTemplate和mybatis框架的整合應用,具有一定的參考價值,感興趣的可以了解一下2022-03-03
Spring Boot啟動過程(六)之內(nèi)嵌Tomcat中StandardHost、StandardContext和Sta
這篇文章主要介紹了Spring Boot啟動過程(六)之內(nèi)嵌Tomcat中StandardHost、StandardContext和StandardWrapper的啟動教程詳解,需要的朋友可以參考下2017-04-04
簡單了解spring bean作用域屬性singleton和prototype的區(qū)別
這篇文章主要介紹了簡單了解spring bean作用域屬性singleton和prototype的區(qū)別,文中通過示例代碼介紹的非常詳細,對大家的學習或者工作具有一定的參考學習價值,需要的朋友可以參考下2019-12-12

