SpringSecutiry整合thymeleaf模板

如何构建SpringSecutiry框架,这里就不详细赘述了,直接速通。

目录

 thymeleaf教程(转载)

 所需的依赖

Thymeleaf模板文件

具体的项目搭建

资源展览图

 接口展示

Thymeleaf模板内容展示


 thymeleaf教程(转载)

Thymeleaf 教程 | 範宗雲 (fanlychie.github.io)

 所需的依赖

        <!--  Spring security依赖      -->
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-security</artifactId>
        </dependency>

        <!-- Thymeleaf 相关依赖 -->
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-thymeleaf</artifactId>
        </dependency>

        <!--引入thymeleaf与Spring Security整合的依赖-->
        <dependency>
            <groupId>org.thymeleaf.extras</groupId>
            <artifactId>thymeleaf-extras-springsecurity5</artifactId>
        </dependency>

Thymeleaf模板文件

<!DOCTYPE HTML>
<html xmlns:th="http://www.thymeleaf.org">
<head>
    <title>Index Page</title>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
</head>
<body>
    <p th:text="${message}">Welcome to BeiJing!</p>
</body>
</html>

具体的项目搭建

资源展览图

 接口展示

package com.ma.controller;

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

/**
 * @author Mtz
 * @version 1.0
 * @2023/6/1810:54
 * @function
 * @comment
 */
@Controller
public class PathController {
    @RequestMapping("/test")
    public String test(Model model){
        model.addAttribute("name","张三");
        model.addAttribute("age","15");
        return "/page/test";
    }
}

Thymeleaf模板内容展示

<!DOCTYPE HTML>
<!-- thymeleaf模板必须引入、 thymeleaf与springsecurity5整合的标签必须引入-->
<html xmlns:th="http://www.thymeleaf.org" xmlns:sec="http://www.thymeleaf.org/thymeleaf-extras-springsecurity5" >
<head>
    <title>SpringBoot模版渲染</title>
    <meta http-equiv="Content-Type" content="text/html;charset=UTF-8"/>
</head>
<body>

<h1 th:text="${name}">1</h1>
<h1 th:text="${age}">2</h1>
</body>
</html>

展示效果

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值