Springboot 集成 Jsp

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/qing_mei_xiu/article/details/80849865

1.pom.xml 添加依赖

<dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter</artifactId>
    <!-- <version>${spring.boot}</version> -->
</dependency>
<!-- tomcat的支持 -->
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-tomcat</artifactId>
        <scope>provided</scope>
    </dependency>
    <dependency>
        <groupId>org.apache.tomcat.embed</groupId>
        <artifactId>tomcat-embed-jasper</artifactId>
        <scope>provided</scope>
    </dependency>

    <!-- servlet依赖. -->
    <dependency>
        <groupId>javax.servlet</groupId>
        <artifactId>javax.servlet-api</artifactId>
        <!-- <scope>provided</scope> -->
    </dependency>

    <dependency>
        <groupId>javax.servlet</groupId>
        <artifactId>jstl</artifactId>
    </dependency>


<resources>
    <!-- 打包时将jsp文件拷贝到META-INF目录下-->
    <resource>
        <!-- 指定resources插件处理哪个目录下的资源文件 -->
        <directory>src/main/webapp</directory>
        <!--注意此次必须要放在此目录下才能被访问到-->
        <targetPath>META-INF/resources</targetPath>
        <includes>
            <include>**/**</include>
        </includes>
    </resource>
    <resource>
        <directory>src/main/resources</directory>
        <includes>
            <include>**/**</include>
        </includes>
        <filtering>false</filtering>
    </resource>
</resources>

2.properties 配置

spring.mvc.view.prefix=/WEB-INF/jsp/
spring.mvc.view.suffix=.jsp

3.注意:
pom.xml 配置 打包需要 war包,如果页面包 404 错误 参考:https://www.cnblogs.com/zwb1234/p/7541617.html

<modelVersion>4.0.0</modelVersion>
<groupId>sinaif-boot-demo</groupId>
<artifactId>hoover</artifactId>
<version>0.0.1-SNAPSHOT</version>

<packaging>war</packaging>

猜你喜欢

转载自blog.csdn.net/qing_mei_xiu/article/details/80849865
今日推荐