Spring boot 整合jsp、thymeleaf、freemarker
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的更多相关文章
- 从零开始的Spring Boot(4、Spring Boot整合JSP和Freemarker)
Spring Boot整合JSP和Freemarker 写在前面 从零开始的Spring Boot(3.Spring Boot静态资源和文件上传) https://www.cnblogs.com/ga ...
- Spring boot整合jsp
这几天在集中学习Spring boot+Shiro框架,因为之前view层用jsp比较多,所以想在spring boot中配置jsp,但是spring boot官方不推荐使用jsp,因为jsp相对于一 ...
- spring boot整合jsp的那些坑(spring boot 学习笔记之三)
Spring Boot 整合 Jsp 步骤: 1.新建一个spring boot项目 2.修改pom文件 <dependency> <groupId>or ...
- Spring boot 整合 Mybatis + Thymeleaf开发web(二)
上一章我把整个后台的搭建和逻辑给写出来了,也贴的相应的代码,这章节就来看看怎么使用Thymeleaf模板引擎吧,Spring Boot默认推荐Thymeleaf模板,之前是用jsp来作为视图层的渲染, ...
- Spring Boot学习总结(2)——Spring Boot整合Jsp
怎么使用jsp上面起了疑问,查阅了多方资料,找到过其他人的博客的描述,也找到了spring在github上的给出的例子,看完后稍微改动后成功 整合jsp,于是决定将整合过程记载下来. 无论使用的是那种 ...
- Spring boot 整合jsp和tiles模板
首先贴上我的pox.xml文件,有详细的支持注释说明 <?xml version="1.0" encoding="UTF-8"?> <proj ...
- Spring Boot整合模板引擎freemarker
jsp本质是servlet,渲染都在服务器,freemarker模板引擎也是在服务器端渲染. 项目结构 引入依赖pom.xml <!-- 引入 freemarker 模板依赖 --> &l ...
- Spring Boot 整合 Shiro+Thymeleaf
1.导包 <!-- springboot 与 shiro 的集成--> <dependency> <groupId>org.apache.shiro</gro ...
- Spring boot 整合JSP开发步骤
1. 新建Springboot项目,war <dependency> <groupId>org.springframework.boot</groupId> < ...
随机推荐
- 访问FTP站点下载文件,提示“当前的安全设置不允许从该位置下载文件”的解决方案
访问FTP站点下载文件,提示“当前的安全设置不允许从该位置下载文件”的解决方案: 打开客戶端浏览器--工具---internet-安全-自定义级别-选择到低到中低. 然后点受信任站点,把你要访问的站点 ...
- JAVA入门2019-JAVA配置(windows7和10通用)IDE推荐和相关软件
如何安装JDK 首先,略过"什么是JDK",非要问,这就是编译环境,JRE是运行环境.一个写程序,一个部署运行. 下载的方法:百度 java se 或者openJDK(两个差不多, ...
- IOS Block动画
● + (void)transitionFromView:(UIView *)fromView toView:(UIView *)toView duration:(NSTimeInterval)dur ...
- IOS 旋转+缩放(手势识别)
@interface NJViewController ()<UIGestureRecognizerDelegate> @property (weak, nonatomic) IBOutl ...
- 待解决问题:c++栈对象的析构、虚拟内存与内存管理的关系、内存管理的解决方案。
待解决问题:c++栈对象的析构.虚拟内存与内存管理的关系.内存管理的解决方案.
- 【洛谷2051】[AHOI2009] 中国象棋(烦人的动态规划)
点此看题面 大致题意: 让你在一张\(N*M\)的棋盘上摆放炮,使其无法互相攻击,问有多少种摆法. 辟谣 听某大佬说这是一道状压\(DP\)题,于是兴冲冲地去做,看完数据范围彻底懵了:\(N≤100\ ...
- Problem I: Satellite Photographs
Problem I: Satellite Photographs Time Limit: 1 Sec Memory Limit: 128 MB Submit: 208 Solved: 118 [S ...
- java 如何使的float保留2位或者多位小数
方法1: float f = 34.232323; BigDecimal b = new BigDecimal(f); float f1 = b.set ...
- 两个list缩进为一个list,python
# w_list = ['a', 'b', 'c', 'd'] # e_list = ['c', 'd', 'b', 'a'] w_list = ['a', 'b', 'c', 'd', 'ff', ...
- 生产环境LAMP搭建 - 基于 fastcgi
生产环境LAMP搭建 - 基于 fastcgi 由于在module模式,php只是已http的模块形式存在,无形中加重了http的服务负载,通常在企业架构中,使用fastcgi的模式,将所有的服务都设 ...