(1)
(2)pom依赖
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<dependency><!-- 添加servlet依赖 -->
<groupId>javax.servlet</groupId>
<artifactId>jstl</artifactId>
<scope>provided</scope>
</dependency>
<dependency><!-- 添加jstl -->
<groupId>javax.servlet</groupId>
<artifactId>jstl</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-tomcat</artifactId>
<scope>provided</scope>
</dependency>
<!-- Need this to compile JSP -->
<dependency>
<groupId>org.apache.tomcat.embed</groupId>
<artifactId>tomcat-embed-jasper</artifactId>
<scope>provided</scope>
</dependency>
</dependencies>
(3)编写controller
@Controller
public class HelloController {
@GetMapping("/aaa")
public String hello(Model model){
model.addAttribute("msg","hello world");
return "success";
}
}
(4)创建webapp文件夹并且导入xml文件
(5)配置yaml文件
spring:
mvc:
view:
prefix: / #标识在webapp下的文件
suffix: .jsp
(6)创建index.jsp文件
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
<title>Title</title>
</head>
<body>
<a href="aaa">aaaa</a>
</body>
</html>
(7)在webapp下创建success.jsp文件
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
<title>Title</title>
</head>
<body>
<h1>${msg}</h1>
</body>
</html>
(8)运行结果
总结:
错误点:
(1)pom依赖导入不全
(2)在springboot中SpringBoot的启动器需要在controller的同一级文件夹
否则任何请求都不能请求成功!!!
这一步自己老是忘,谨记谨记!!!!,创建文件夹不规范,或者在添加扫描文件路径