1.添加依赖(由于springboot本身不支持解析jsp)
<!-- tomcat的支持.-->
<dependency>
<groupId>org.apache.tomcat.embed</groupId>
<artifactId>tomcat-embed-jasper</artifactId>
<scope>provided</scope>
</dependency>
2.在main创建 webapp文件夹 --》WEB-INF文件夹--》jsp文件夹--》jsp文件
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>helloword</title>
</head>
<body>
<%
out.println("Hello World!");
%>
</body>
</html>
3.配置文件添加
spring:
mvc:
view:
suffix: .jsp
prefix: /WEB-INF/jsp/
4.java controller层
@RequestMapping(value = "/test4")
public String test4(Person person,Model model) {
model.addAttribute("person","qwer");
// System.out.println(person);
// System.out.println(abc);
return "demo";
}
5.页面访问 http://locahost:8080/test4