【任雨杰真帅啊】 3. SpringBoot中Web模板数据渲染展示

我打算创建一个专栏,主要用于结合八股文和各种场景题来进行代码实践,包括但不限制于集成各种中间件去实现对应的场景和工具封装,该文章为SpringBoot专栏的一个系列,希望大家观看以后帮我多多点赞评论。


大家的点赞和关注是我创作的动力,实属不易,谢谢大家~

📕 引入依赖

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

📕 resources/templates/添加index.html

image-20231031142501666

<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
</head>
<h2>一行</h2>
<table>
    <tr>
        <td th:text="${name} + '是一个特别漂亮知性、温柔体贴、如沐春风的女孩子'"></td>
    </tr>
    <tr>
        <td th:text="'你会对她一辈子特别好吗?(yes/no) ' + ${flag}"></td>
    </tr>
</table>

📕 application.properties 增加配置

spring.freemarker.suffix=.html

📕 TestController增加接口

@Controller
public class TestController {

    @GetMapping("/hello")
    public String helloTest(){
        return "hello,world";
    }
    @RequestMapping("/index")
    public String index2(ModelMap m){
        //数据也可以从数据库查询出来返回
        m.addAttribute("name", "耿晓如");
        m.addAttribute("flag", "yes");
        //返回是一个页码:src/main/resources/templates/index.html
        return "index";
    }
}
  • 5
    点赞
  • 7
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值