圖解如何在Spring Boot中使用JSP頁(yè)面
一、創(chuàng)建webapp目錄
在src/main下創(chuàng)建webapp目錄,用于存放jsp文件。這就是一個(gè)普通的目錄,無(wú)需執(zhí)行Mark Directory As
二、創(chuàng)建jsp
1、指定web資源目錄
在spring boot工程中若要?jiǎng)?chuàng)建jsp文件,一般是需要在src/main下創(chuàng)建webapp目錄,然后在該目錄下創(chuàng)建jsp文件。但通過(guò)Alt + Insert發(fā)現(xiàn)沒(méi)有創(chuàng)建jsp文件的選項(xiàng)。此時(shí),需要打開(kāi)Project Structrue窗口,將webapp目錄指定為web資源目錄,然后才可以創(chuàng)建jsp文件。
指定后便可看到下面的窗口情況。
此時(shí),便可在webapp中找到j(luò)sp的創(chuàng)建選項(xiàng)了。
2、創(chuàng)建index.jsp頁(yè)面與welcome.jsp頁(yè)面
三、添加jasper依賴
在pom中添加一個(gè)Tomcat內(nèi)嵌的jsp引擎jasper依賴。
<dependency><groupId>org.apache.tomcat.embed</groupId><artifactId>tomcat-embed-jasper</artifactId></dependency>
四、注冊(cè)資源目錄
在pom文件中將webapp目錄注冊(cè)為資源目錄
<build><resources><!--注冊(cè)webapp目錄為資源目錄--><resource><directory>src/main/webapp</directory><targetPath>META-INF/resources</targetPath><includes><include>**/*.*</include></includes></resource></resources> <plugins><plugin><groupId>org.springframework.boot</groupId><artifactId>spring-boot-maven-plugin</artifactId></plugin></plugins></build>
不過(guò),我們一般會(huì)添加兩個(gè)資源目錄:
<resources><!--注冊(cè)Dao包目錄下Mybatis映射文件資源目錄--><resource><directory>src/main/java</directory><includes><include>**/*.xml</include></includes></resource> <!--注冊(cè)webapp目錄為資源目錄--><resource><directory>src/main/webapp</directory><targetPath>META-INF/resources</targetPath><includes><include>**/*.*</include></includes></resource></resources>
四、創(chuàng)建Controller
五、邏輯視圖配置
六、訪問(wèn)
以上就是本文的全部?jī)?nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持好吧啦網(wǎng)。
相關(guān)文章:
1. python中scrapy處理項(xiàng)目數(shù)據(jù)的實(shí)例分析2. Django ORM實(shí)現(xiàn)按天獲取數(shù)據(jù)去重求和例子3. 教你在 IntelliJ IDEA 中使用 VIM插件的詳細(xì)教程4. IntelliJ IDEA導(dǎo)入jar包的方法5. Python requests庫(kù)參數(shù)提交的注意事項(xiàng)總結(jié)6. js抽獎(jiǎng)轉(zhuǎn)盤實(shí)現(xiàn)方法分析7. 快速搭建Spring Boot+MyBatis的項(xiàng)目IDEA(附源碼下載)8. python操作mysql、excel、pdf的示例9. 如何基于Python實(shí)現(xiàn)word文檔重新排版10. vue-electron中修改表格內(nèi)容并修改樣式
