欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  IT编程

Spring boot 添加jsp支持配置详解

程序员文章站 2023-12-20 14:42:34
spring boot添加对jsp的支持,以下是pom.xml文件的配置

spring boot添加对jsp的支持,以下是pom.xml文件的配置

<project xmlns="http://maven.apache.org/pom/4.0.0" xmlns:xsi="http://www.w3.org/2001/xmlschema-instance" 
  xsi:schemalocation="http://maven.apache.org/pom/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"> 
  <modelversion>4.0.0</modelversion> 
 
  <groupid>spring_web_boot</groupid> 
  <artifactid>spring_web_boot_base</artifactid> 
  <packaging>war</packaging> 
 
  <version>0.0.1-snapshot</version> 
  <name>spring_web_boot_base maven webapp</name> 
  <url>http://maven.apache.org</url> 
 
 
  <!-- 继承父包,此包会添加依赖,spring用到的核心包--> 
  <parent> 
    <groupid>org.springframework.boot</groupid> 
    <artifactid>spring-boot-starter-parent</artifactid> 
    <version>1.4.0.release</version> 
    <relativepath></relativepath> 
  </parent> 
 
  <!-- spring-boot的web启动的jar包 --> 
  <dependencies> 
    <dependency> 
      <groupid>org.springframework.boot</groupid> 
      <artifactid>spring-boot-starter-web</artifactid> 
    </dependency> 
 
    <!--jpa的jar包 ,操作数据库的,类似hibernate --> 
    <dependency> 
      <groupid>org.springframework.boot</groupid> 
      <artifactid>spring-boot-starter-data-jpa</artifactid> 
    </dependency> 
 
    <!--mysql驱动 --> 
    <dependency> 
      <groupid>mysql</groupid> 
      <artifactid>mysql-connector-java</artifactid> 
    </dependency> 
 
    <!--配置servlet--> 
    <dependency> 
      <groupid>javax.servlet</groupid> 
      <artifactid>javax.servlet-api</artifactid> 
    </dependency> 
 
    <!--配置jsp jstl的支持--> 
    <dependency> 
      <groupid>javax.servlet</groupid> 
      <artifactid>jstl</artifactid> 
    </dependency> 
 
    <!--添加对tomcat的支持--> 
    <dependency> 
      <groupid>org.springframework.boot</groupid> 
      <artifactid>spring-boot-starter-tomcat</artifactid> 
      <scope>provided</scope> 
    </dependency> 
 
    <!--对jsp的支持--> 
    <dependency> 
      <groupid>org.apache.tomcat.embed</groupid> 
      <artifactid>tomcat-embed-jasper</artifactid> 
    </dependency> 
  </dependencies> 
 
  <!-- package as an executable jar --> 
  <build> 
    <plugins> 
      <plugin> 
        <groupid>org.springframework.boot</groupid> 
        <artifactid>spring-boot-maven-plugin</artifactid> 
      </plugin> 
    </plugins> 
  </build> 
 
  <!-- allow access to spring milestones and snapshots --> 
  <!-- (you don't need this if you are using anything after 0.5.0.release) --> 
  <repositories> 
    <repository> 
      <id>spring-snapshots</id> 
      <url>http://repo.spring.io/snapshot</url> 
      <snapshots> 
        <enabled>true</enabled> 
      </snapshots> 
    </repository> 
    <repository> 
      <id>spring-milestones</id> 
      <url>http://repo.spring.io/milestone</url> 
      <snapshots> 
        <enabled>true</enabled> 
      </snapshots> 
    </repository> 
  </repositories> 
  <pluginrepositories> 
    <pluginrepository> 
      <id>spring-snapshots</id> 
      <url>http://repo.spring.io/snapshot</url> 
    </pluginrepository> 
    <pluginrepository> 
      <id>spring-milestones</id> 
      <url>http://repo.spring.io/milestone</url> 
    </pluginrepository> 
  </pluginrepositories> 
</project> 

针对如上的配置分为2中情况

1.当parent标签中引入的是1.4.0版本的话,那么applicaion.properties中配置jsp前缀和后缀的时候应该配置如下,一定要带上mvc

spring.mvc.view.prefix=/web-inf/jsp/
spring.mvc.view.suffix=.jsp

2.当parent标签中引入的是1.1.3版本的话,那么applicaion.properties中配置jsp前缀和后缀的时候应该配置如下,一定不要带上mvc

spring.view.prefix=/web-inf/jsp/
spring.view.suffix=.jsp

注意事项:

<dependency>
  <groupid>org.apache.tomcat.embed</groupid>
  <artifactid>tomcat-embed-jasper</artifactid>
</dependency>

针对如上在pom.xml中配置一定不要加上作用于为provided

最后附带上maven settings.xml中添加阿里云的maven路径,可以提高下载速度

<mirror>
    <id>nexus-aliyun</id>
    <mirrorof>*</mirrorof>
    <name>nexus aliyun</name>
    <url>http://maven.aliyun.com/nexus/content/groups/public</url>
  </mirror> 

以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持。

上一篇:

下一篇: