thymeleaf模板引擎

1.模板引擎

导入thymeleaf后,可以使用controller来打开相应的页面
image

2.代码

<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
</head>
<body>
<div th:text = "${msg}"></div>
</body>
</html>

后端代码:

package com.shao.controller;

import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

//在template下面的页面只能通过controller获取
@Controller
public class IndexController {

    @ResponseBody
    @RequestMapping("/index")
    public String index(Model model){
        model.addAttribute("msg", "Hello,SpringBoot!");
        return "index!";
    }
}

posted @   蘑菇王国大聪明  阅读(47)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· 阿里最新开源QwQ-32B,效果媲美deepseek-r1满血版,部署成本又又又降低了!
· Manus重磅发布:全球首款通用AI代理技术深度解析与实战指南
· 开源Multi-agent AI智能体框架aevatar.ai,欢迎大家贡献代码
· 被坑几百块钱后,我竟然真的恢复了删除的微信聊天记录!
· AI技术革命,工作效率10个最佳AI工具
点击右上角即可分享
微信分享提示