如何构建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>
展示效果