spring boot-thymeleaf

thymleaf

官网:

https://www.thymeleaf.org/

spring boot 文档 starter地址,当需要集成模块时:

https://docs.spring.io/spring-boot/docs/2.2.6.RELEASE/reference/html/using-spring-boot.html#using-boot-starter

 

thymeleaf是什么?

一个现代的服务器端java template 引擎。 可以处理html xml javascrip css 甚至text.

Thymeleaf is a modern server-side Java template engine for both web and standalone environments, capable of processing HTML, XML, JavaScript, CSS and even plain text.

The main goal of Thymeleaf is to provide an elegant and highly-maintainable way of creating templates. To achieve this, it builds on the concept of Natural Templates to inject its logic into template files in a way that doesn’t affect the template from being used as a design prototype. This improves communication of design and bridges the gap between design and development teams.

Thymeleaf has also been designed from the beginning with Web Standards in mind – especially HTML5 – allowing you to create fully validating templates if that is a need for you.

 

thymeleaf的作用?

联结前端页面和后端数据桥梁。和以前的jsp作用类似。

thymleaf怎么用? 

在springboot中使用:

1.添加依赖  从springboot 官网获得

        <dependency>
            <groupId>org.thymeleaf</groupId>
            <artifactId>thymeleaf-spring5</artifactId>
        </dependency>
        <dependency>
            <groupId>org.thymeleaf.extras</groupId>
            <artifactId>thymeleaf-extras-java8time</artifactId>
        </dependency>

2.  从类ThymeleafProperties可以发现,thymeleaf的html应该放在classpath:/templates

public static final String DEFAULT_PREFIX = "classpath:/templates/";构建项目时,已自动创建该目录.

 

3.访问前台静态页面

templates目录下面的html,可以通过controller转发访问:

package com.wang.controller;


import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
public class HellowController {

    @RequestMapping("/hello")
    public String hello(){
        return "Hello world!";
    }

    @RequestMapping("/thymeleaf")
    public String helloThymeleaf(){
        return "helloThymeleaf";
    }
}

 

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值