项目下载地址:http://download.csdn.NET/detail/aqsunkai/9805821
(一)pom中添加依赖:
<!-- https://mvnrepository.com/artifact/org.apache.tomcat.embed/tomcat-embed-jasper --> <!--配置支持jsp--> <dependency> <groupId>org.apache.tomcat.embed</groupId> <artifactId>tomcat-embed-jasper</artifactId> <version>8.5.12</version> </dependency> <!-- https://mvnrepository.com/artifact/javax.servlet/javax.servlet-api --> <dependency> <groupId>javax.servlet</groupId> <artifactId>javax.servlet-api</artifactId> <version>3.1.0</version> </dependency> <!-- https://mvnrepository.com/artifact/javax.servlet/jstl --> <dependency> <groupId>javax.servlet</groupId> <artifactId>jstl</artifactId> <version>1.2</version> </dependency>
项目结构如下:
jsp和resources文件夹都在WEB-INF目录下
配置文件application.yml中加入:
spring:
mvc:
view:
prefix: /WEB-INF/jsp/
suffix: .jsp
static-path-pattern: /**
resources:
static-locations: classpath:/WEB-INF/resources/
启动类需要继承SpringBootServletInitializer类并重写其中configure方法
@Override protected SpringApplicationBuilder configure(SpringApplicationBuilder builder) { return builder.sources(this.getClass()); }
jsp页面引用资源文件方法:
<script src="<%=basePath%>js/jquery-2.1.4/jquery.min.js"></script>