SpringBoot中使用Thymeleaf
- pom依赖
org.springframework.boot spring-boot-starter-thymeleaf com.github.theborakompanioni thymeleaf-extras-shiro ${thymeleaf-shiro.version}
- 配置项
spring: ## thymeleaf模板设置 thymeleaf: prefix: classpath:/templates suffix: .html mode: HTML encoding: utf-8 servlet.content-type: text/html cache: false
- 创建LoginController控制器,loginPage函数用来显示登陆页
@Controllerpublic class LoginController { @GetMapping("/login") public String loginPage(Model model) { ProjectProperties properties = SpringApplicationContextUtil.getBean(ProjectProperties.class); model.addAttribute("isCaptcha", properties.isCaptchaOpen()); return "/login"; }}
- 创建templates模板目录,并创建login.html登录页
login.html
EasyBoot登录