springboot中訪問jsp文件方式

首先,添加加載jsp文件的依賴包:java

<!--jsp依賴 對應springboot版本爲2.1.4-->
<dependency>
<groupId>org.apache.tomcat.embed</groupId>
<artifactId>tomcat-embed-jasper</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>jstl</artifactId>
</dependency>
再添加webapp/WEB-INF/jsp文件夾,以下圖:

以後,咱們在properties文件中添加
spring.mvc.view.prefix=/
spring.mvc.view.suffix=.jsp
最後一步最重要,在pom.xml文件中的build節點下添加以下內容,謹記
<resources>
<resource>
<directory>src/main/webapp/WEB-INF/jsp</directory>
<!--若是使用springboot自帶的tomcat啓動,則使用以下配置jsp路徑-->
<targetPath>META-INF/resources</targetPath>
<!--若是使用maven啓動本地tomcat啓動,則使用以下配置-->
<!--<targetPath>/WEB-INF/jsp</targetPath>-->
<includes>
<include>**/*.*</include>
</includes>
</resource>
</resources>
注意以上幾點後,便可在controller層訪問jsp文件了。
相關文章
相關標籤/搜索