整合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的更多相关文章

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

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

  2. springboot配置server相关配置&整合模板引擎Freemarker、thymeleaf&thymeleaf基本用法&thymeleaf 获取项目路径 contextPath 与取session中信息

    1.Springboot配置server相关配置(包括默认tomcat的相关配置) 下面的配置也都是模板,需要的时候在application.properties配置即可 ############## ...

  3. JAVA SpringBoot2 整合 JSP视图模板 整合 Ueditor富文本编辑器

    一般涉及到后台管理系统,就少不了富文本编辑器,这个可以图,文,视频混排的高级工具,笔者通过对比,发现目前市场上最好的三方库还当属百度的 ueditor 近年来 SpringBoot 框架可谓越来越火, ...

  4. SpringBoot整合Jsp和Thymeleaf (附工程)

    前言 本篇文章主要讲述SpringBoot整合Jsp以及SpringBoot整合Thymeleaf,实现一个简单的用户增删改查示例工程.事先说明,有三个项目,两个是单独整合的,一个是将它们整合在一起的 ...

  5. SpringBoot第九集:整合JSP和模板引擎Freemarker/Thymeleaf(2020最新最易懂)

    SpringBoot第九集:整合JSP和模板引擎(2020最新最易懂) 当客户通过前端页面提交请求后,我们以前是怎么做的?后端接收请求数据,处理请求,把响应结果交给模板引擎JSP,最后将渲染后的JSP ...

  6. 整合Freemarker视图层和整合jsp视图层和全局捕获异常

    SpringBoot静态资源访问 1.静态资源:访问 js / css /图片,传统web工程,webapps springboot 要求:静态资源存放在resource目录下(可以自定义文件存放) ...

  7. springboot整合JSP以及发布项目到独立的tomcat中与打成jar包使用

    之前研究了springboot整合freemarker与thymeleaf的使用.也研究了springboot发布到独立的tomcat的使用以及使用自带的tomcat打成jar包的使用,下面研究集成J ...

  8. 【SpringBoot】常用Starter介绍和整合模板引擎Freemaker、thymeleaf

    ========7.SpringBoot常用Starter介绍和整合模板引擎Freemaker.thymeleaf ========================= 1.SpringBoot Sta ...

  9. SpringBoot常用Starter介绍和整合模板引擎Freemaker、thymeleaf 4节课

    1.SpringBoot Starter讲解 简介:介绍什么是SpringBoot Starter和主要作用 1.官网地址:https://docs.spring.io/spring-boot/doc ...

随机推荐

  1. BZOJ 1596: [Usaco2008 Jan]电话网络 树形DP

    挺经典的,细节需要特别注意一下 Code: #include<bits/stdc++.h> using namespace std; #define setIO(s) freopen(s& ...

  2. BZOJ 1492: [NOI2007]货币兑换Cash 斜率优化 + splay动态维护凸包

    Description 小Y最近在一家金券交易所工作.该金券交易所只发行交易两种金券:A纪念券(以下简称A券)和 B纪念券(以下 简称B券).每个持有金券的顾客都有一个自己的帐户.金券的数目可以是一个 ...

  3. ps磨皮的方法

    磨皮顾名思义就是将皮肤模糊掉,它可以去除皮肤上的一些斑点以及细纹,从而使皮肤看起来更加光滑.下面就是两张磨皮前后的对比图,很明显右边的人物的皮肤看起来要更好一些:给人的视觉效果也更年轻一点. 磨皮前后 ...

  4. HTML 浅层漫谈

    讲到HTML最主要的就是如何给这个网页搭架子给他大致的把这个人物样子先慢慢画出来,然后我们后面去学习这个CSS还有JS的时候给这个雏形慢慢的去加一些东西,让你的网页变得越来越好看 1.标签的使用 a: ...

  5. crazyflie四轴飞行器

    源地址:http://www.bitcraze.se/2013/02/pre-order-has-started/ Crazyflie是一个开源的纳米四旋翼 来几张靓照 开发平台是开源的,所以原理图和 ...

  6. Android7.1后对于Toast类型窗口的限制

    在处理问题的时候,经常会遇到ANR,停止运行等问题,经过分析和验证,和如下的一行关键log有关 WindowManager: Adding more than one toast window for ...

  7. Learn Python the hard way, ex35 分支和函数

    #!/usr/bin/python #coding:utf-8 from sys import exit def gold_room(): print "this room is full ...

  8. JS动态添加Easyui的HTML时样式丢失

    解决办法: $.parser.parse($("#creatLi").html(<li>xxxxxx</li>)); ------------------- ...

  9. 如何在Python中使用Linux epoll

    如何在Python中使用Linux epoll 内容 介绍 阻塞套接字编程示例 异步套接字和Linux epoll的好处 epoll的异步套接字编程示例 性能考量 源代码 介绍 从2.6版开始,Pyt ...

  10. Linux系统的镜像文件iso下载地址

    CentOS-6.1-x86_64-bin-DVD1.iso 官方网址:http://archive.kernel.org/centos-vault/6.1/isos/x86_64/ 下载链接地址:h ...