thymeleaf模板引擎

文章介绍了在SpringBoot项目中使用Thymeleaf模板引擎的基本配置,包括添加依赖、ThymeleafProperties的配置以及如何通过@Controller和@RequestMapping处理视图渲染。还提到前端与后端交互时的参数传递和配置细节。
摘要由CSDN通过智能技术生成

导入相关依赖

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

ThymeleafProperties 配置类

1.默认编码

2.前缀

3.后缀

相当于视图解析器 

package com.kuang.controller;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

@Controller
//templates在这个目录下的所有页面,只能通过controller来访问,相当于一起的WEB-INF目录
//需要导入模板引擎
//模板引擎是视图解析器,只能通过服务器转发,请求是请求不到的,拼接获取html,静态资源实现的是,路径映射。有优先级。
public class IndexController {

    @RequestMapping("/index")
    public String index(){
        return "/test";
    }

}

 

这是学SpringBoot的必经之路,非常重要!!!(除非你是学前端的)

 

只改了前端代码点一下这个就可以刷新 

    @RequestMapping("/index")
    public String index(Model model){
        model.addAttribute("msg","hello springboot");
        return "/test";
    }

 

传值过来了 

th:text="${msg}"爆红,但是可以显示,File->Settings->Editor->Inspection  取消“Expression variables validation”的勾选

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值