根据B站中黑马程序员所讲解的SpringSecurity内容所做的记录。
一.实现自定义设置登录页面
1.在配置类SecurityConfigTest3.java
中实现相应的配置
2.在resources中建立static文件夹(默认找这里面的页面)
创建login.html
<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org">
<head>
<meta charset="UTF-8">
<title>static中的login</title>
</head>
<body>
<form action="/user/login" method="post">
用户名:<input type="text" name="username"/>
<br/>
密码:<input type="text" name="password"/>
<br/>
<input type="submit" value="login"/>
</form>
</body>
</html>
注意:其中username和password是固定的
但是是可以自定义的,但是在这里使用默认的
3.controller文件:
@RestController
@RequestMapping("/test")
public class TestController {
@GetMapping("hello")
public String add(){
return "hello security";
}
@GetMapping("index")
public String add2(){
return "hello index";
}
}
4.测试
访问:http://localhost:8888/test/hello
出现:hello security
访问:http://localhost:8888/test/index
会跳转到
出现:
输入与数据库对应的用户名和密码后,显示:
hello index