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 ...
随机推荐
- jsqlparser
摘要:SQL语法解释器jsqlparser 是用java开发的解析器,可以生成java类层次结构. 主页地址:http://jsqlparser.sourceforge.net 可以完美解析表的增删查 ...
- pycharm默认的模板修改python script
#!/usr/bin/env python # encoding: utf-8 #set( $SITE = "https://www.cnblogs.com/c-x-a" ) &q ...
- HttpClient请求服务器图片
我们先引入一个IO流相关的Jar包, 从apache下载 下载后,jar包和源码如图: 我们只需要将jar包引入项目: 之后我们使用FileUtils这个类,其中有一个文件复制方法. 我们将请求的图片 ...
- Gradle查看Project中的所有 Task
查看Project中所有的Task:$ gradle tasks 查看Project中所有的properties:$ gradle properties 如: 参照了: https://www.jia ...
- day22—一个AngularJS框架应用toDoList
转行学开发,代码100天——2018-04-07 今天用AngularJS照着课程写了一个案例,即toDoList,记事清单效果. 主要实现以下效果: 1.通过文本框添加内容,同时添加事件列表.主要用 ...
- EntityFramework经典数据访问层基类——增删改查
namespace StudentSys.DAL { public class BaseService<T>:IDisposable where T:BaseEntity,new() { ...
- postman测试wsdl类型接口
1 IP地址来源搜索 WEB 服务 接口信息 http://www.webxml.com.cn/WebServices/WeatherWebService.asmx?wsdl 2 设置接口调用地址 ...
- Spring MVC浅析
讲到MVC,想必大家都很熟悉,就是将数据模型.视图.控制器进行分离,做到分工明确,在Spring的帮助下,Spring MVC 更是做到了充分的解耦,因为大部分的资源都由Spring进行管理,为Spr ...
- reuseaddr和点对点聊天
解决绑定失败 在测试时,经常会出现绑定错误,bind error: Address already in use 这里只要指定一下socket的reuseaddr属性即可解决 int on=1; if ...
- python time 和日期相关模块
时间日期相关的模块 calendar 日历模块 time 时间模块 datetime 日期时间模块 timeit 时间检测模块 日历模块 calendar() 功能:获取指定年份的日历字符串 格式:c ...