SpringBoot 整合 thymeleaf

1. pom.xml 加入 Thymeleaf 启动器

   <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-thymeleaf</artifactId>
        </dependency>

2. 将 HTML 页面放到 classpath:/templates/ 目录下, Thymeleaf 就能自动渲染

3,编写controller

package com.example.demo.controller;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.Map;

@Controller
public class HelloController {
    @ResponseBody
    @GetMapping("/execute")
    public String execute () {
        return "success";
    }
}

注意这里不要使用  RestController 否则返回的是字符串 不是页面

4. 浏览器访问

http://localhost:8080/execute

5.将操作层的数据填写入模板中

导入 Thymeleaf 的名称空间

在 html 页面加上以下名称空间, 使用 Thymeleaf 时就有语法提示。

<html xmlns:th="http://www.thymeleaf.org">

原文地址:https://www.cnblogs.com/guangzhou11/p/12391421.html

时间: 2024-08-30 17:55:55

SpringBoot 整合 thymeleaf的相关文章

Spring Boot入门系列六( SpringBoot 整合thymeleaf)

SpringBoot 整合thymeleaf 一.什么是Thymeleaf模板 Thymeleaf是一款用于渲染XML/XHTML/HTML5内容的模板引擎.类似JSP,Velocity,FreeMaker等,它也可以轻易的与Spring MVC等Web框架进行集成作为Web应用的模板引擎.与其它模板引擎相比,Thymeleaf最大的特点是能够直接在浏览器中打开并正确显示模板页面,而不需要启动整个Web应用.它的功能特性如下: @Controller中的方法可以直接返回模板名称,接下来Thyme

三、SpringBoot整合Thymeleaf

三.SpringBoot整合Thymeleaf As well as REST web services, you can also use Spring MVC to serve dynamic HTML content. Spring MVC supports a variety of templating technologies, including Thymeleaf, FreeMarker, and JSPs. Also, many other templating engines

SpringBoot:2.SpringBoot整合Thymeleaf模板引擎渲染web视图

在Web开发过程中,Spring Boot可以通过@RestController来返回json数据,那如何渲染Web页面?Spring Boot提供了多种默认渲染html的模板引擎,主要有以下几种: Thymeleaf FreeMarker Velocity Groovy Mustache Spring Boot 推荐使用这些模板引擎来代替 Jsp,Thymeleaf 只是其中一种,下面我们来简单聊聊Thymeleaf及实践一下如何整合Spring Boot和Thymeleaf. 1.Thyme

SpringBoot整合Thymeleaf(三)

? Thymeleaf是SpringBoot官方推荐的用来渲染页面的一个模板,如果你对模板和模板引擎没什么概念的话,可以简单理解为Thymeleaf是一个高级简洁的JSP.如果学过MVC设计模式,那么Thymeleaf就是视图层(view)的主要核心内容. 为什么要整合Thymeleaf SpringBoot在内置Tomcat服务器,并且以Jar包方式运行,传统JSP页面不在适合这种模式开发 使用Thymeleaf有助于前后端协作,因为它在无网络环境下也可以运行,前端开发者便于在静态页面查看页面

springboot整合Thymeleaf模板引擎

引入依赖 需要引入Spring Boot的Thymeleaf启动器依赖. <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-thymeleaf</artifactId> </dependency> <dependency> <groupId>nekohtml</groupId&g

SpringBoot学习9:springboot整合thymeleaf

1.创建maven项目,添加项目所需依赖 <!--springboot项目依赖的父项目--> <parent> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-parent</artifactId> <version>2.0.0.RELEASE</version> </parent> <de

springboot 整合 thymeleaf的问题

org.thymeleaf.exceptions.TemplateInputException org.thymeleaf.exceptions.TemplateInputException: Error resolving template "Hello", template might not exist or might not be accessible by any of the configured Template Resolvers 因为springboot 是2.0版

springBoot整合thymeleaf时th:onclick事件

今天按照 <JavaEE开发的颠覆者: Spring Boot实战> 学习spring boot的时候在编写7_2时thymeleaf传参的时候发生500错误,通过查找各方面资料,发现书上的springboot版本(1.3.0)和我用的版本(2.1.7)不一样引起的 以下处理方法: 1.   将springboot版本改成2.0.5 2.   3.x版本的thymeleaf为了防止注入攻击,升级了安全机制 解决 修改前 <button th:onclick="'javascri

springboot整合thymeleaf——引用静态资源

原html src="/css/index.css" thymeleaf中,th:src="@{/css/index.css}" 原文地址:https://www.cnblogs.com/fangwr/p/11939243.html

SpringBoot整合Thymeleaf

简介: 在目前的企业级应用开发中 前后端分离是趋势,但是视图层技术还占有一席之地, Spring Boot 对视图层技术提供了很好的支持,官方推荐使用的模板引擎是 Thymeleaf 不过像 FreeMarker 也支持, JSP 技术在这里并不推荐使用. Thymeleaf 是新一代 Java 模板引擎,类似于 Velocity.FreeMarker 等传统 Java 模板引擎.与传统 Java 模板引擎不同的是 Thymeleaf 支持 HTML 原型,既可 以让前端工程师在浏览器中直接打