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 @ 2022-01-10 16:56  蘑菇王国大聪明  阅读(55)  评论(0)    收藏  举报