首先,構建一個簡單的Web工程,以用於後續添加安全控制,也能夠用以前Chapter3-1-2作爲基礎工程。若對如何使用Spring Boot構建Web應用,能夠先閱讀《Spring Boot開發Web應用》一文。html
@Controller public class HelloController { @RequestMapping("/") public String index() { return "index"; } @RequestMapping("/hello") public String hello() { return "hello"; } }
/
:映射到index.html/hello
:映射到hello.html<!DOCTYPE html> <html xmlns="http://www.w3.org/1999/xhtml" xmlns:th="http://www.thymeleaf.org" xmlns:sec="http://www.thymeleaf.org/thymeleaf-extras-springsecurity3"> <head> <title>Spring Security入門</title> </head> <body> <h1>歡迎使用Spring Security!</h1> <p>點擊 <a th:href="@{/hello}">這裏</a> 打個招呼吧</p> </body> </html>
src/main/resources/templates/hello.htmlgit
<!DOCTYPE html> <html xmlns="http://www.w3.org/1999/xhtml" xmlns:th="http://www.thymeleaf.org" xmlns:sec="http://www.thymeleaf.org/thymeleaf-extras-springsecurity3"> <head> <title>Hello World!</title> </head> <body> <h1>Hello world!</h1> </body> </html>
能夠看到在index.html中提供到/hello
的連接,顯然在這裏沒有任何安全控制,因此點擊連接後就能夠直接跳轉到hello.html頁面。web