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> < ...
随机推荐
- linux中BASH_SOURCE[0](转)
转自:http://www.cnblogs.com/sunfie/p/5943979.html 在C/C++中,__FUNCTION__常量记录当前函数的名称.有时候,在日志输出的时候包含这些信息是非 ...
- 【BZOJ1059】[ZJOI2007] 矩阵游戏(匈牙利算法)
点此看题面 大致题意: 有一个\(N*N\)的\(01\)矩阵,可以任意交换若干行和若干列,问是否有方案使得左上角到右下角的连线上全是\(1\). 题意转换 首先,让我们来对题意进行一波转化. 如果我 ...
- python_47_Python2中字符编码与转码
#python3默认是Unicode,Unicode是万国码,不管中文字符还是英文,所有的每个字符都占2个字节空间,16位 #python2默认是ascii码 #ascii码不能存中文,一个英文只能占 ...
- python_40_通过脚本转换参数实现替换
import sys f=open('yesterday','r',encoding='utf-8') f_new=open('yesterday_update','w',encoding='utf- ...
- Spring学习记录(二)
1.Spring中的AOP思想 aop思想:横向重复,纵向抽取. AOP(Aspect-OrientedProgramming,面向切面编程),AOP包括切面(Aspect),通知(Advice),连 ...
- java基础编程——用两个栈来实现一个队列
题目描述 用两个栈来实现一个队列,完成队列的Push和Pop操作. 队列中的元素为int类型. 题目代码 /** * <分析>: * 入队:将元素进栈A * 出队:判断栈B是否为空, * ...
- windows下sorl安装
1. JDK要求 Solr 4.10 要求JDK版本必须是1.7或更高. 2. 下载 下载地址: http://www.apache.org/dyn/closer.cgi/lucene/solr/ 下 ...
- C++ 容器与继承
如果容器类型定义为基类类型,那么虽然可以把派生类装进容器中,但是不能通过容器访问派生类自己的public成员,派生类将会倍切掉,只保留派生类的基类部分: 如果把容器定义为派生类类型,那么不能把基类类型 ...
- 《转载》ASP动态iframe
原文:[ASP.NET]关于iframe的两个技巧 最近在给朋友写个网站,虽然不大,但是也碰到了一些问题.这篇就为解决ASP.NET中关于IFRAME的两个很现实的问题提供解决方法.PS:呵呵,又做了 ...
- <转载>一般筛法和快速线性筛法求素数
素数总是一个比较常涉及到的内容,掌握求素数的方法是一项基本功. 基本原则就是题目如果只需要判断少量数字是否为素数,直接枚举因子2 ..N^(0.5) ,看看能否整除N. 如果需要判断的次数较多,则先用 ...