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);
}

}

分别运行调试。

注意各文件位置

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

Spring boot 整合jsp、thymeleaf、freemarker的更多相关文章

  1. 从零开始的Spring Boot(4、Spring Boot整合JSP和Freemarker)

    Spring Boot整合JSP和Freemarker 写在前面 从零开始的Spring Boot(3.Spring Boot静态资源和文件上传) https://www.cnblogs.com/ga ...

  2. Spring boot整合jsp

    这几天在集中学习Spring boot+Shiro框架,因为之前view层用jsp比较多,所以想在spring boot中配置jsp,但是spring boot官方不推荐使用jsp,因为jsp相对于一 ...

  3. spring boot整合jsp的那些坑(spring boot 学习笔记之三)

    Spring Boot 整合 Jsp 步骤: 1.新建一个spring boot项目 2.修改pom文件 <dependency>            <groupId>or ...

  4. Spring boot 整合 Mybatis + Thymeleaf开发web(二)

    上一章我把整个后台的搭建和逻辑给写出来了,也贴的相应的代码,这章节就来看看怎么使用Thymeleaf模板引擎吧,Spring Boot默认推荐Thymeleaf模板,之前是用jsp来作为视图层的渲染, ...

  5. Spring Boot学习总结(2)——Spring Boot整合Jsp

    怎么使用jsp上面起了疑问,查阅了多方资料,找到过其他人的博客的描述,也找到了spring在github上的给出的例子,看完后稍微改动后成功 整合jsp,于是决定将整合过程记载下来. 无论使用的是那种 ...

  6. Spring boot 整合jsp和tiles模板

    首先贴上我的pox.xml文件,有详细的支持注释说明 <?xml version="1.0" encoding="UTF-8"?> <proj ...

  7. Spring Boot整合模板引擎freemarker

    jsp本质是servlet,渲染都在服务器,freemarker模板引擎也是在服务器端渲染. 项目结构 引入依赖pom.xml <!-- 引入 freemarker 模板依赖 --> &l ...

  8. Spring Boot 整合 Shiro+Thymeleaf

    1.导包 <!-- springboot 与 shiro 的集成--> <dependency> <groupId>org.apache.shiro</gro ...

  9. Spring boot 整合JSP开发步骤

    1. 新建Springboot项目,war <dependency> <groupId>org.springframework.boot</groupId> < ...

随机推荐

  1. 浅谈Scrum敏捷开发:4个输入/输出、3个关键物、3个会议

    文章对Scrum敏捷开发流程进行系统的分析,希望借此文能够加深你对敏捷开发的认知,更好的展开产品工作. Scrum敏捷开发,是一种敏捷开发框架,是一个增量的.迭代的开发过程,具备可视.可集成和可运行使 ...

  2. Java的几种加载驱动的方法

    1.Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver"); 2.DriverManager.registerD ...

  3. pat乙级1034

    1.vs2013不能用scanf,改为scanf_s,但是提交时不能用scanf_s,用scanf... scanf_s(], &a[], &b[], &b[]); 2.c++ ...

  4. linux 命令——5 rm(转)

    昨天学习了创建文件和目录的命令mkdir ,今天学习一下linux中删除文件和目录的命令: rm命令.rm是常用的命令,该命令的功能为删除一个目录中的一个或多个文件或目录,它也可以将某个目录及其下的所 ...

  5. PHP:isset()-检测变量是否被设置

    isset()-检测变量是否被设置 bool isset(mixed $var [, mixed $...]),检查变量是否被设置,并且不是NULL.var,要检测的变量,...其他变量,允许有多个变 ...

  6. EF和linq语句查询条件不等于某个参数出现的问题

    where t.a!=字符串   这是错误的写法,正确为 where t.a!=字符串.trim() 其他类型变量需要保持实体类型和查询条件参数的类型是一致的,不然出现的语句可能会是 类似`Exten ...

  7. DongDong跳一跳

    题目连接:https://ac.nowcoder.com/acm/contest/904/C 题意很好理解,思路想歪了,本来一道很简单的题,写了好久没写出来. 思路就是找每一个高度最大值的时候就是找“ ...

  8. OO第四单元总结

    单元架构设计 本单元OO作业主要涉及两个过程,即先根据输入的elements数组建立UML存储模型,而后基于这个模型实现一系列查询判断功能.汲取上单元的经验,建模过程中模型数据容器的选择依据要求实现的 ...

  9. bootstrap table 自定义checkbox样式

    //css <style> .checkbox-custom { position: relative; padding: 0 15px 0 25px; margin-bottom: 7p ...

  10. package.json字段分析

    分析1.必须在包的顶层目录下2.二进制文件应该在bin目录下3.javascipt在lib目录下4.文档在doc目录下 package.json字段分析 name:包的名称,必须是唯一的,由小写英文字 ...