您好,登錄后才能下訂單哦!
這篇“SpringMVC RESTFul訪問首頁(yè)怎么實(shí)現(xiàn)”文章的知識(shí)點(diǎn)大部分人都不太理解,所以小編給大家總結(jié)了以下內(nèi)容,內(nèi)容詳細(xì),步驟清晰,具有一定的借鑒價(jià)值,希望大家閱讀完這篇文章能有所收獲,下面我們一起來看看這篇“SpringMVC RESTFul訪問首頁(yè)怎么實(shí)現(xiàn)”文章吧。
在 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> <h2>首頁(yè)</h2> <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>
點(diǎn)擊 配置。
繼續(xù)按照順序點(diǎn)擊配置。
選擇要部署的 war 包,點(diǎn)擊確定。
最后為了方便訪問,修改下上下文(不改也可以)。
點(diǎn)擊部署,成功后自動(dòng)打開首頁(yè)。
以上就是關(guān)于“SpringMVC RESTFul訪問首頁(yè)怎么實(shí)現(xiàn)”這篇文章的內(nèi)容,相信大家都有了一定的了解,希望小編分享的內(nèi)容對(duì)大家有幫助,若想了解更多相關(guān)的知識(shí)內(nèi)容,請(qǐng)關(guān)注億速云行業(yè)資訊頻道。
免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如果涉及侵權(quán)請(qǐng)聯(lián)系站長(zhǎng)郵箱:is@yisu.com進(jìn)行舉報(bào),并提供相關(guān)證據(jù),一經(jīng)查實(shí),將立刻刪除涉嫌侵權(quán)內(nèi)容。