1、创建项目
2、修改pom文件,添加坐标
![](https://i-blog.csdnimg.cn/blog_migrate/1ed359691cffb1e30dc8200ef080dfde.png)
3、创建springBoot的全局配置文件,application.properties
![](https://i-blog.csdnimg.cn/blog_migrate/5d2b517c9038b6299f5d7715823baa4b.png)
# mav视图配置
spring.mvc.view.prefix=/WEB-INF/jsp/
spring.mvc.view.suffix=.jsp
spring.mvc.view.suffix=.jsp
4、创建Controller
package com.lxp.controller;
import java.util.ArrayList;
import java.util.List;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import com.lxp.pojo.User;
@Controller
public class ShowUserController {
@RequestMapping("/showUser")
public String showUser(Model model) {
List<User> list = new ArrayList<User>();
list.add(new User(1, "张三", 20));
list.add(new User(2, "李四", 22));
list.add(new User(3, "王五", 24));
model.addAttribute("list", list);
return "userList";
}
}
pojo类
package com.lxp.pojo;
public class User {
private Integer userId;
private String userName;
private Integer age;
public Integer getUserId() {
return userId;
}
public void setUserId(Integer userId) {
this.userId = userId;
}
public String getUserName() {
return userName;
}
public void setUserName(String userName) {
this.userName = userName;
}
public Integer getAge() {
return age;
}
public void setAge(Integer age) {
this.age = age;
}
public User(int id, String name, int age) {
this.userId = id;
this.userName = name;
this.age = age;
}
}
5、创建jsp
![](https://i-blog.csdnimg.cn/blog_migrate/80846c875defcd9af49b3977da688cbf.png)
<%@page import="org.apache.tomcat.util.descriptor.tld.TaglibXml"%>
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<!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>
<table border="1" align="center" width="50%">
<tr>
<th>ID</th>
<th>Name</th>
<th>Age</th>
</tr>
<c:forEach items="${list}" var="user">
<tr>
<td>${user.userId }</td>
<td>${user.userName }</td>
<td>${user.age }</td>
</tr>
</c:forEach>
</table>
</body>
</html>
6,创建启动类
@SpringBootApplication
public class App {
public static void main(String[] args) {
SpringApplication.run(App.class, args);
}
}