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 @   billwen  阅读(11)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· 分享一个免费、快速、无限量使用的满血 DeepSeek R1 模型,支持深度思考和联网搜索!
· 基于 Docker 搭建 FRP 内网穿透开源项目(很简单哒)
· ollama系列1:轻松3步本地部署deepseek,普通电脑可用
· 按钮权限的设计及实现
· 【杂谈】分布式事务——高大上的无用知识?
点击右上角即可分享
微信分享提示