java-SpringBoot 首页实现(thymeleaf-index.html)

上结果

在这里插入图片描述

1.蓝奏云资源

在这里插入图片描述

https://rod.lanzous.com/b0dkgezdc

2.扩展mvc:添加视图控制器

@Configuration
public class MyMvcConfig implements WebMvcConfigurer {
  @Override
  public void addViewControllers(ViewControllerRegistry registry) {
    // 路径"/"-跳转到index
    registry.addViewController("/").setViewName("index");
    // 路径"/index"-跳转到index
    registry.addViewController("/index").setViewName("index");
  }
}

3.index页面

图片,css资源位置
在这里插入图片描述

<!doctype html>
<!--添加thymeleaf命名空间 xmlns:th="http://www.thymeleaf.org"-->
<html lang="en" xmlns:th="http://www.thymeleaf.org">
  <head>
    <meta 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="Mark Otto, Jacob Thornton, and Bootstrap contributors">
    <meta name="generator" content="Jekyll v4.1.1">
    <title>Signin Template · Bootstrap</title>
<!--这一行是不要的-->
<!--    <link rel="canonical" href="https://getbootstrap.com/docs/4.5/examples/sign-in/">-->

    <!-- Bootstrap core CSS -->
    <!--th:表示由thymeleaf接管 @{}:是导入路径 内容是从静态文件夹(pubilc,static,resources)下寻找/css/bootstrap.min.css-->
<link th:href="@{/css/bootstrap.min.css}"
      rel="stylesheet">

    <style>
      .bd-placeholder-img {
        font-size: 1.125rem;
        text-anchor: middle;
        -webkit-user-select: none;
        -moz-user-select: none;
        -ms-user-select: none;
        user-select: none;
      }

      @media (min-width: 768px) {
        .bd-placeholder-img-lg {
          font-size: 3.5rem;
        }
      }
    </style>
    <!-- Custom styles for this template -->
    <!--同上-->
    <link th:href="@{/css/signin.css}" rel="stylesheet">
  </head>
  <body class="text-center">
    <form class="form-signin">
      <!--同上.由thymeleaf接管 路径@{}-->
  <img class="mb-4" th:src="@{/img/bootstrap-solid.svg}" alt="" width="72" height="72">
  <h1 class="h3 mb-3 font-weight-normal">Please sign in</h1>
  <label for="inputEmail" class="sr-only">Email address</label>
  <input type="email" id="inputEmail" class="form-control" placeholder="Email address" required autofocus>
  <label for="inputPassword" class="sr-only">Password</label>
  <input type="password" id="inputPassword" 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">&copy; 2017-2020</p>
</form>
</body>
</html>

4.yaml配置:thymeleaf关闭缓存

@ConfigurationProperties(prefix = "spring.thymeleaf")
public class ThymeleafProperties {
	private boolean cache = true;
	public void setCache(boolean cache) {
		this.cache = cache;
	}
}
spring:
  thymeleaf:
    cache: false

已标记关键词 清除标记
©️2020 CSDN 皮肤主题: 游动-白 设计师:上身试试 返回首页