230126_50_SpringBoot入门

  • 4.首页实现
  • 自定义配置
package com.bill.config;

import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.ViewControllerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

/**
 * @Auther: wangchunwen
 * @Date: 2023/1/26 - 01 - 26 - 14:46
 * @Description: com.bill.config
 * @version: 1.0
 */

@Configuration
public class MyMvcConfig implements WebMvcConfigurer {
    @Override
    public void addViewControllers(ViewControllerRegistry registry) {
        registry.addViewController("/").setViewName("index");
        registry.addViewController("/index.html").setViewName("index");
    }
}

测试结果:


可以发现静态资源没有加载进来,出现了乱码,需要修改相关thymeleaf配置。

  • 修改index.html
  • (1)导入命名空间
<html lang="en" xmlns:th="http://www.thymeleaf.org">
  • (2)链接,本地的链接需要修改,在线的链接不需要修改。
<!-- Bootstrap core CSS -->
<link th:href="@{/css/bootstrap.min.css}" rel="stylesheet">
<!-- Custom styles for this template -->
<link th:href="@{/css/signin.css}" rel="stylesheet">
  • (3)图片
<img class="mb-4" th:src="@{/img/bootstrap-solid.svg}" alt="" width="72" height="72">

测试结果:静态资源正常导入

  • 同理,修改其他html静态资源
  • 首页配置注意点:所有页面的静态资源需要使用thymeleaf接管;@{}
posted @ 2023-01-26 17:16  billwen  阅读(18)  评论(0)    收藏  举报