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接管;@{}
分类:
每天写50行代码
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 分享一个免费、快速、无限量使用的满血 DeepSeek R1 模型,支持深度思考和联网搜索!
· 基于 Docker 搭建 FRP 内网穿透开源项目(很简单哒)
· ollama系列1:轻松3步本地部署deepseek,普通电脑可用
· 按钮权限的设计及实现
· 【杂谈】分布式事务——高大上的无用知识?