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

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 2
    评论
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值