进阶SpringBoot之首页和图标定制

idea 快捷键:

ctrl + shift + "+" 使缩起来的代码展开

ctrl + shitf + "-" 使代码缩起

WebMvcAutoConfiguration.class:可以看到需要有一个 index.html 文件映射到首页

java 复制代码
        private Resource getIndexHtmlResource(Resource location) {
            try {
                Resource resource = location.createRelative("index.html");
                if (resource.exists() && resource.getURL() != null) {
                    return resource;
                }
            } catch (Exception var3) {
            }

            return null;
        }

resources 目录下 任意一个(图片上有的)都能存放 index.html,随便写个首页两字

(放在 templates 目录下的所有页面,只能通过 controller 来跳转)

如果放在 templates 包下,需要有 thymeleaf 插件

java 复制代码
package com.demo.web.controller;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

@Controller
public class IndexController {
    //在templates目录下的所有页面,只能通过controller来跳转
    @RequestMapping ("/index")
    public String index(){
        return "index";
    }
}

同理,把图片命名为 favicon.ico,放到 resources 目录任意一个包下

启动查看效果:

图标成功显示!

相关推荐
小刘|8 分钟前
Spring WebFlux + AI 流式输出深度解析:Spring AI 与 LangChain4j 效果差异溯源
java·后端·spring
Arvin.Angela13 分钟前
Maven 的基本配置操作
java·maven
夕除14 分钟前
Spring Security 配置类(SecurityConfig)
java·后端·spring
lfwh16 分钟前
探针程序技术解析:基于 Spring Boot 非 Web 模式的云服务监控告警系统
前端·spring boot·后端
weixin1997010801617 分钟前
[特殊字符] 1688开放平台API Sign签名算法详解(Java / Python / PHP 实现)
java·python·算法
武子康22 分钟前
Java-22 深入浅出 MyBatis - 手写ORM框架3 手写SqlSession、Executor 工作原理
java·后端
未若君雅裁29 分钟前
JVM 垃圾回收算法与分代回收机制
java·jvm·算法
ikoala31 分钟前
Codex 不得不装的 12 个插件,都在这了
前端·javascript·后端
摇滚侠1 小时前
SpringMVC 入门到实战 简介和入门案例 01-13
java·后端·spring·intellij-idea
未若君雅裁1 小时前
JVM 垃圾回收器全景与G1深度解析
java·开发语言·jvm