第一步:创建wabapp maven项目工程
第二步:在pom.xml文件引入以下依赖
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>1.5.9.RELEASE</version>
</parent>
<dependencies>
<!-- SpringBoot 核心组件 -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-tomcat</artifactId>
</dependency>
<dependency>
<groupId>org.apache.tomcat.embed</groupId>
<artifactId>tomcat-embed-jasper</artifactId>
</dependency>
</dependencies>
第三步:在src/main下,建立resources文件夹,再建文件application.properties,并配置以下属性。最后,在webapp/WEB-INF文件夹下,建立teacher文件夹,让后建立list.jsp文件
list.jsp文件
<%--
Created by IntelliJ IDEA.
User: 韩杰
Date: 2021/4/12
Time: 20:09
To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
<title>Title</title>
</head>
<body>
hanjie:这是我写的内容
</body>
</html>
spring.mvc.view.prefix=/WEB-INF/view/
spring.mvc.view.suffix=.jsp
第五步:准备控制代码,我写了一个TeacherController控制器
package com.hanjie.web;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.web.bind.annotation.RequestMapping;
@EnableAutoConfiguration
@RequestMapping("teacher")
public class TeacherController {
@RequestMapping("list")
public String list(){
return "teacher/list";
}
public static void main(String [] args){
SpringApplication.run(TeacherController.class,args);
}
}
第六步,在浏览器中查看结果,如图