springboot新增jsp的支持
一、添加依赖
<!-- 添加对jsp的支持 --> <!-- web 依赖 --> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-web</artifactId> <exclusions> <exclusion> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-logging</artifactId> </exclusion> </exclusions> </dependency> <!-- servlet 依赖 --> <dependency> <groupId>javax.servlet</groupId> <artifactId>javax.servlet-api</artifactId> <scope>provided</scope> </dependency> <!-- 添加 JSTL(JSP Standard Tag Library,JSP标准标签库) --> <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> <dependency> <groupId>org.apache.tomcat.embed</groupId> <artifactId>tomcat-embed-jasper</artifactId> </dependency>
二、创建jsp目录和页面
<%@ page language="java" contentType="text/html; charset=utf-8" pageEncoding="utf-8"%> <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8"> <title>Insert title here</title> </head> <body> Hello!!! </body> </html>
三、application.properties配置文件的完善
#----------------------------jsp-------------------------------- spring.mvc.view.prefix=/WEB-INF/jsp/ spring.mvc.view.suffix=.jsp
四、创建控制器
@RestController @ApiIgnore public class LoginController { @RequestMapping(value="/login") public String hello(){ return "login"; } }
启动springboot项目并访问
这时就可以写自己想写的页面了,web目录可以没有