首页 > 编程语言 > 详细

SpringBoot 整合 thymeleaf

时间:2020-03-01 20:11:13      阅读:30      评论:0      收藏:0      [点我收藏+]
1. pom.xml 加入 Thymeleaf 启动器
   <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-thymeleaf</artifactId>
        </dependency>

2. 将 HTML 页面放到 classpath:/templates/ 目录下, Thymeleaf 就能自动渲染

技术分享图片

 

 

3,编写controller

package com.example.demo.controller;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.Map;

@Controller
public class HelloController {
    @ResponseBody
    @GetMapping("/execute")
    public String execute () {
        return "success";
    }
}

注意这里不要使用  RestController 否则返回的是字符串 不是页面

4. 浏览器访问  

http://localhost:8080/execute

 

 

技术分享图片

 

5.将操作层的数据填写入模板中

导入 Thymeleaf 的名称空间
在 html 页面加上以下名称空间, 使用 Thymeleaf 时就有语法提示。
<html xmlns:th="http://www.thymeleaf.org">

 

 

SpringBoot 整合 thymeleaf

原文:https://www.cnblogs.com/guangzhou11/p/12391421.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!