07.整合jsp、整合freemarker、整合thymeleaf
整合jsp
pom.xml部分内容
<packaging>war</packaging>
</dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-tomcat</artifactId>
</dependency>
<!--用于编译jsp -->
<dependency>
<groupId>org.apache.tomcat.embed</groupId>
<artifactId>tomcat-embed-jasper</artifactId>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-war-plugin</artifactId>
<version>2.3</version>
<configuration>
<failOnMissingWebXml>false</failOnMissingWebXml>
</configuration>
</plugin>
</plugins>
</build>
spring.mvc.view.prefix=/WEB-INF/
spring.mvc.view.suffix=.jsp
src/main/webapp/WEB-INF/index.jsp
<body>
<h4>${name}</h4>
</body>
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
@Controller
public class Index2Controller {
@RequestMapping("/index")
public String show(Model model){
model.addAttribute("name","李四");
return "index";
}
}
整合freemarker
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-freemarker</artifactId>
</dependency>
src/main/resources/templates
# freemarker静态资源配置
# 设定ftl文件路径 #默认是就是classpath:/templates 此条可以省略
spring.freemarker.template-loader-path=classpath:/templates
# 默认false 关闭缓存,及时刷新,上线生产环境需要修改为true
spring.freemarker.cache=false
# 默认utf-8
spring.freemarker.charset=utf-8
# 默认true
spring.freemarker.check-template-location=true
# 默认text/html
spring.freemarker.content-type=text/html
# 默认false
spring.freemarker.expose-request-attributes=false
spring.freemarker.expose-spring-macro-helpers=false
# 默认false
spring.freemarker.expose-session-attributes=false
spring.freemarker.request-context-attribute=request
spring.freemarker.suffix=.ftl
index.ftl
<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport"
content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>index</title>
</head>
<body>
<h4>index.ftl</h4>
<h4>${name}</h4>
</body>
</html>
整合thymeleaf
<!--引入thymeleaf的依赖-->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-thymeleaf</artifactId>
</dependency>
<dependency>
<groupId>net.sourceforge.nekohtml</groupId>
<artifactId>nekohtml</artifactId>
</dependency>
</dependencies>
# 关闭缓存,开发时使用
spring.thymeleaf.cache=false
# 检查模版是否存在,然后再呈现,默认true
spring.thymeleaf.check-template-location=true
# 模版编码 默认HTML5,是严格html5校验,LEGACYHTML5依赖nekohtml
spring.thymeleaf.mode=LEGACYHTML5
# 默认classpath:/templates/
spring.thymeleaf.prefix=classpath:/templates/
# 默认.html
spring.thymeleaf.suffix=.html
index.html
<body>
<h1 th:text="${name}"></h1>
</body>
07.整合jsp、整合freemarker、整合thymeleaf的更多相关文章
- 从零开始的Spring Boot(4、Spring Boot整合JSP和Freemarker)
Spring Boot整合JSP和Freemarker 写在前面 从零开始的Spring Boot(3.Spring Boot静态资源和文件上传) https://www.cnblogs.com/ga ...
- springboot配置server相关配置&整合模板引擎Freemarker、thymeleaf&thymeleaf基本用法&thymeleaf 获取项目路径 contextPath 与取session中信息
1.Springboot配置server相关配置(包括默认tomcat的相关配置) 下面的配置也都是模板,需要的时候在application.properties配置即可 ############## ...
- JAVA SpringBoot2 整合 JSP视图模板 整合 Ueditor富文本编辑器
一般涉及到后台管理系统,就少不了富文本编辑器,这个可以图,文,视频混排的高级工具,笔者通过对比,发现目前市场上最好的三方库还当属百度的 ueditor 近年来 SpringBoot 框架可谓越来越火, ...
- SpringBoot整合Jsp和Thymeleaf (附工程)
前言 本篇文章主要讲述SpringBoot整合Jsp以及SpringBoot整合Thymeleaf,实现一个简单的用户增删改查示例工程.事先说明,有三个项目,两个是单独整合的,一个是将它们整合在一起的 ...
- SpringBoot第九集:整合JSP和模板引擎Freemarker/Thymeleaf(2020最新最易懂)
SpringBoot第九集:整合JSP和模板引擎(2020最新最易懂) 当客户通过前端页面提交请求后,我们以前是怎么做的?后端接收请求数据,处理请求,把响应结果交给模板引擎JSP,最后将渲染后的JSP ...
- 整合Freemarker视图层和整合jsp视图层和全局捕获异常
SpringBoot静态资源访问 1.静态资源:访问 js / css /图片,传统web工程,webapps springboot 要求:静态资源存放在resource目录下(可以自定义文件存放) ...
- springboot整合JSP以及发布项目到独立的tomcat中与打成jar包使用
之前研究了springboot整合freemarker与thymeleaf的使用.也研究了springboot发布到独立的tomcat的使用以及使用自带的tomcat打成jar包的使用,下面研究集成J ...
- 【SpringBoot】常用Starter介绍和整合模板引擎Freemaker、thymeleaf
========7.SpringBoot常用Starter介绍和整合模板引擎Freemaker.thymeleaf ========================= 1.SpringBoot Sta ...
- SpringBoot常用Starter介绍和整合模板引擎Freemaker、thymeleaf 4节课
1.SpringBoot Starter讲解 简介:介绍什么是SpringBoot Starter和主要作用 1.官网地址:https://docs.spring.io/spring-boot/doc ...
随机推荐
- springmvc上传文件异常
症状: error:org.springframework.web.multipart.MultipartException: Current request is not a multipart r ...
- MapServer教程2
第二章 Tutorial 教程 MapServer Tutorial MapServer教程 Tutorial background 教程背景 Section 1: Static Maps and t ...
- Linux系统中imp导入dmp文件
[oracle@ocm1 ~]$ lltotal 32-rw-r--r-- 1 oracle oinstall 24576 Mar 27 15:26 COUNTRIES.dmpdrwxr-xr-x 2 ...
- QT | 第二章 基本语法
''' @Modify Time @Author ------------ ------- python基本语法 2019/10/26 8:16 laoalo ''' import functools ...
- linux之yum源的RPM软件包管理
1.yum源的配置文件 路径:vim /etc/yum.repos.d/CnetOS-Base.repo 文件格式: 2.yum查询 yum list 查询所有可用软件包 yum search 包名 ...
- django缓存优化(二)
一.缓存目的: 1.减小过载 2.避免重复计算 3.提高系统性能 二.如何进行缓存 三.缓存类型 四.缓存粒度分类 五.缓存的设置与使用 示例一: CACHES = { 'default': { 'B ...
- 凉经-Mozilla Firefox Ltd
北京谋智火狐信息技术有限公司(北京市东城区建国门华润大厦17层)过去面试的时候感觉电梯好神奇啊!一边的电梯是直达18层以上的,我按了18层准备到了再往下走一层,一个老司机和我说要做另一边的1-17层的 ...
- MYSQL数据库中的查询语句
查询的方法 *简单查询:select * from 表名 (* = 所有的) *读取特定列:select 字段一,字段二 from 表名 *条件查询:select * from 表名 where (多 ...
- delphi 获取文件的最新修改时间 http://www.delphitop.com/html/wenjian/64.html
delphi 获取文件的最新修改时间 作者:admin 来源:未知 日期:2010/1/28 13:15:22 人气:1054 标签: QQ空间新浪微博腾讯微博腾讯朋友QQ收藏百度空间百度贴吧更多0 ...
- 【BASIS系列】SAP 设置系统timeout时间
公众号:SAP Technical 本文作者:matinal 原文出处:http://www.cnblogs.com/SAPmatinal/ 原文链接:[BASIS系列]SAP 设置系统timeout ...