spring boot thymeleaf引擎访问HTML页面
2019-03-05 20:32
465 查看
1,pom文件添加
[code]<!--thymeleaf模板引擎--> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-thymeleaf</artifactId> </dependency>
2 login.html页面,放到templates目录下
[code]<!DOCTYPE html> <html lang="en" xmlns:th="http://www.thymeleaf.org"> <head> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no"> <meta name="description" content=""> <meta name="author" content=""> <title>Signin Template for Bootstrap</title> <!-- Bootstrap core CSS --> <!--都可以用th来引用--> <link href="asserts/css/bootstrap.min.css" th:href="@{/webjars/bootstrap/4.0.0/css/bootstrap.css}" rel="stylesheet"> <!-- Custom styles for this template --> <link href="asserts/css/signin.css" rel="stylesheet"> </head> <body class="text-center"> <form class="form-signin" action="dashboard.html"> <img class="mb-4" th:src="@{/asserts/img/bootstrap-solid.svg}" src="asserts/img/bootstrap-solid.svg" alt="" width="72" height="72"> <h1 class="h3 mb-3 font-weight-normal">Please sign in</h1> <label class="sr-only">Username</label> <input type="text" class="form-control" placeholder="Username" required="" autofocus=""> <label class="sr-only">Password</label> <input type="password" class="form-control" placeholder="Password" required=""> <div class="checkbox mb-3"> <label> <input type="checkbox" value="remember-me"> Remember me </label> </div> <button class="btn btn-lg btn-primary btn-block" type="submit">Sign in</button> <p class="mt-5 mb-3 text-muted">© 2017-2018</p> <a class="btn btn-sm">中文</a> <a class="btn btn-sm">English</a> </form> </body> </html>
3,配置文件
[code]server.port=8080 #自定义静态资源路径--其他路径的静态资源不起作用 #spring.resources.static-locations=classpath:/hello/,classpath:/comp/ #thymelea模板配置 spring.thymeleaf.prefix=classpath:/templates/ spring.thymeleaf.suffix=.html spring.thymeleaf.mode=HTML5 spring.thymeleaf.encoding=UTF-8 #配置项目访问路径 server.servlet.context-path=/crud #热部署文件,页面不产生缓存,及时更新 spring.thymeleaf.cache=false spring.resources.chain.strategy.content.enabled=true spring.resources.chain.strategy.content.paths=/**
4. 写一个配置类,当项目访问localhost:8080直接跳转到login.html
[code]@Configuration public class MymvcConfig implements WebMvcConfigurer { @Override public void addViewControllers(ViewControllerRegistry registry) { //login22,请求来到success registry.addViewController("/login22").setViewName("login"); } @Bean //将组件注册到容器中 public WebMvcConfigurer webMvcConfigurer(){ WebMvcConfigurer adp=new WebMvcConfigurer(){ @Override public void addViewControllers(ViewControllerRegistry registry) { registry.addViewController("/").setViewName("login"); registry.addViewController("/index.html").setViewName("login"); } }; return adp; } }
启动项目,访问localhost:8080
相关文章推荐
- springboot如何使用thymeleaf模板访问html页面
- SpringBoot直接访问HTML页面
- Springboot怎么访问html页面
- [spring boot] 用 thymeleaf模板开发html页面
- springboot 使用 thymeleaf 模板引擎。在页面写隐藏域接收后台的值。在页面进行对话框提示。
- 访问不存在的Thymeleaf 资源时使页面转向 404,而不是500 (Spring Boot)
- 【系统学习SpringBoot】初见Thymeleaf之SpringBoot访问项目中的 jsp/html
- spring-boot配置html模板引擎freemarker、thymeleaf
- thymeleaf :springboot整合mybatis的web项目中使用html而不是jsp当页面渲染
- springboot-thymeleaf(html页面跳转)
- springboot--页面访问拦截器
- 利用Nginx负载均衡的访问SpringBoot服务,还有如何利用Nginx实现404,500等错误页面的拦截
- springBoot项目用jar包 访问不到页面
- JavaEE开发之SpringBoot整合MyBatis以及Thymeleaf模板引擎
- Springboot系列:Springboot与Thymeleaf模板引擎整合基础教程(附源码)
- [spring boot][thymeleaf]spring boot 1.5+ 页面无法找到
- springboot跳转html页面
- SpringBoot使用thymeleaf模板引擎
- Spring Boot---(16)Spring Boot使用Thymeleaf开发web页面
- Spring Boot使用thymeleaf 解析html template时失败