在 pom 文件中增加thymeleaf页面支持
<!-- 引入页面模板 -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-thymeleaf</artifactId>
</dependency>
application.yml 配置文件
创建 resources 目录文件夹目录为: src/main/resources 并将其设置为 resource 资源目录, 在resources目录下创建 application.yml 配置文件
spring:
thymeleaf:
cache: false
check-template: true
check-template-location: true
content-type: text/html
enabled: true
encoding: UTF-8
mode: HTML5
prefix: classpath:/templates/
suffix: .html
在resources目录下创建 templates 文件目录, 并在该目录下创建 index.html 和 login.html 页面文件
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<title>SpringBoot Security Integration</title>
</head>
<body>
</body>
</html>
login 页面
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<title>登录页面</title>
</head>
<body>
<form action="" method="post">
<table>
<tr>
<td>用户名:</td>
<td><input name="username" id="username" value=""/></td>
</tr>
<tr>
<td>密码:</td>
<td><input name="password" id="password" value=""/></td>
</tr>
<tr>
<td colspan="2"><input type="submit" value="submit" /></td>
</tr>
</table>
</form>
</body>
</html>
controller目录下跳转配置
在 java 源码目录下创建controller目录, 并在该目录下创建 HomeController/UserController 进行页面跳转配置
package com.edurt.controller;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
@Controller
public class HomeController {
@RequestMapping(value = "/", method = RequestMethod.GET)
String home() {
return "index";
}
}
UserController
package com.edurt.controller;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
@Controller
@RequestMapping(value = "user")
public class UserController {
@RequestMapping(value = "login", method = RequestMethod.GET)
String login() {
return "login";
}
@RequestMapping(value = "logout", method = RequestMethod.GET)
String logout() {
return "login";
}
}
以上就是SpringBoot整合Security权限控制登录首页的详细内容,更多关于SpringBoot整合Security登录的资料请关注编程网其它相关文章!