首页 > 编程语言 > 详细

SpringBoot集成Thymeleaf模板

时间:2020-05-17 15:16:39      阅读:40      评论:0      收藏:0      [点我收藏+]

 1,pom.xml,引入依赖

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

2,application.properties配置

#Thymeleaf配置
spring.thymeleaf.cache=false
spring.thymeleaf.encoding=utf-8
spring.thymeleaf.mode=HTML5
spring.thymeleaf.prefix=classpath:/templates
spring.thymeleaf.suffix=.html

2,文件目录

技术分享图片

3,controller

package alu.controller;

import javax.servlet.http.HttpServletRequest;

import org.apache.ibatis.annotations.Delete;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import com.github.pagehelper.PageHelper;

import alu.bean.User;
import alu.service.TestService;
import alu.util.JwtUtils;
import io.jsonwebtoken.Claims;

@Controller
@RequestMapping("/user")
public class TestController {
    @Autowired
    private TestService test;
    
     
     
     @RequestMapping(value = "/index")
     public String index(HttpServletRequest request){
         
         PageHelper.startPage(0, 10);
         request.setAttribute("test", test.findAllVideo());
        
          return "/user/index";
                 
     }
     
     @RequestMapping(value = "/indexT")
     public String isndex(HttpServletRequest request){
         
        
         request.setAttribute("test", "asdasda");
        
          return "/index";
                 
     }
     
 
     

}

4,html存放位置

技术分享图片

5,user里的index页面

<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org">

<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">

<title>index</title>
</head>
<body>
    <div class="row">
        <div class="col-md-5">
            <table class="table table-hover" id="tab">
                <thead>
                    <tr>

                        <th>id</th>
                        <th>title</th>
                        <th>summary</th>
                        
                        <th>操作</th>
                    </tr>
                </thead>
                <tbody>
                    <tr th:each="ItemList : ${test}">
                        <td th:text="${ItemList.id }"></td>
                        <td th:text="${ItemList.title }"></td>
                <td th:text="${ItemList.summary }"></td>
                    </tr>
                

                </tbody>



            </table>

        </div>
    </div>


</body>
</html>

效果:

技术分享图片

 

SpringBoot集成Thymeleaf模板

原文:https://www.cnblogs.com/mangoubiubiu/p/12905306.html

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