1.创建spring boot 项目

2、pom文件配置如下:

<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<!-- jsp -->
<dependency>
<groupId>org.apache.tomcat.embed</groupId>
<artifactId>tomcat-embed-jasper</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>jstl</artifactId>
</dependency>
<!-- freemarker -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-freemarker</artifactId>
</dependency>
<!-- thymeleaf -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-thymeleaf</artifactId>
</dependency>
</dependencies>

3、编写controller

@Controller
public class ShowUserController {

@RequestMapping("/showuser")
public String showUser(Model model) {

List<user> list = new ArrayList<user>();

list.add(new user("1","张三","23"));

list.add(new user("2","李斯","26"));

list.add(new user("3","汪汪","25"));

list.add(new user("4","嘿咻","24"));

model.addAttribute("userList",list);

//thymeleaf 例子
return "thymeleaf";
//freemarker 例子
//return "userShow";
//jsp 例子
//return "userindex";
}

}

4、页面

(1)thymeleaf.html

<html>
<head>
<title>springboot-freemarker测试</title>
<meta charset='utf-8'/>
</head>

<body>
<table border=1 align="center" width="50%">

<tr>
<td>ID</td>
<td>NAME</td>
<td>AGE</td>
</tr>
<tr th:each=" user : ${userList} ">
<td th:text="${user.userId}"></td>
<td th:text="${user.userName}"></td>
<td th:text="${user.userAge}"></td>
</tr>
</table>

</body>
</html>

(2)userShow.ftl

<html>
<head>
<title>springboot-freemarker测试</title>
<meta charset='utf-8'/>
</head>

<body>
<table border=1 align="center" width="50%">

<tr>
<td>ID</td>
<td>NAME</td>
<td>AGE</td>
</tr>
<#list userList as user >
<tr>
<td th:text="${user.userId}"></td>
<td th:text="${user.userName}"></td>
<td th:text="${user.userAge}"></td>
</tr>
</#list>

</table>

</body>
</html>

(3)userindex.jsp

<%@ taglib prefix="spring" uri="http://www.springframework.org/tags"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@ page language="java" contentType="text/html; charset=utf-8" pageEncoding="utf-8"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8"/>
<title>用户展示</title>

</head>
<body>
<table border=1 align="center" width="50%">

<tr>
<td>ID</td>
<td>NAME</td>
<td>AGE</td>
</tr>
<c:forEach var="user" items="${userList}" >
<tr>
<td>${user.userId}</td>
<td>${user.userName}</td>
<td>${user.userAge}</td>
</tr>
</c:forEach>

</table>
</body>
</html>

注:jsp 额外配置 application.properties 文件

//jsp 位置

spring.mvc.view.prefix=/WEB-INF/jsp/

//jsp后缀
spring.mvc.view.suffix=.jsp

5编写启动类

@SpringBootApplication
public class App {

public static void main(String[] args) {
// TODO Auto-generated method stub

SpringApplication.run(App.class, args);
}

}

分别运行调试。

注意各文件位置

本人初学。请各位大佬多多指点。谢谢

最新文章

  1. Python基础+Pythonweb+Python扩展+Python选修四大专题 超强麦子学院Python35G视频教程
  2. 【vijos1243】 生产产品
  3. oracle触发器设置uuid变量
  4. Sublime Text 3 3126 注册码
  5. c#和数据库技术基础之程序设计集散地-数据库
  6. Extjs4.2.1中的helloworld
  7. 解决数据标准及质量AppScan(测试)安全性问题相关方法
  8. Systemd 入门教程:命令篇
  9. Windows玩转Docker(二):运行whalesay image
  10. 一个人ACM(我们赶上了ACM)
  11. EM and GMM(Code)
  12. 微软Skype Linux客户端全新发布
  13. MongoDB更需要好的模式设计 及 案例赏析
  14. Perl 正则匹配经验记录
  15. 【PgSQL安装(含配置)】PostgreSQL简称PgSQL,是1980以加利福尼亚大学开发的DBMS,严格遵守标准SQL。
  16. perl 函数
  17. 如何让移植的嵌入式ARM显示中文汉字
  18. SVN 基本的工作循环
  19. Android 判断是否是Rtl
  20. kibana 安装

热门文章

  1. es6 随笔
  2. Redis分片(分区)
  3. IBM中国
  4. 前端面试题1:Object.prototype.toString.call() 、instanceof 以及 Array.isArray()三种方法判别数组的优劣和区别
  5. Struts2 In Action笔记_页面到动作的数据流入和流出
  6. Mint UI文档
  7. package.json字段分析
  8. HTTP 配置与编译安装
  9. SQL Server字符串聚合拼接办法
  10. JavaScript算数