进阶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 目录任意一个包下

启动查看效果:

图标成功显示!

相关推荐
未秃头的程序猿几秒前
🚀 别再手写 RabbitMQ 样板代码了!这个开源 Starter 让消息队列集成只需 5 分钟
后端·rabbitmq
洛阳泰山2 分钟前
开源智能体搭建平台MaxKB4j 技术文档
java·开源·llm·springboot·agent·rag·langchain4j
我命由我123458 分钟前
Android 开发 - UriMatcher(一个 URI 分类器)
android·java·java-ee·kotlin·android studio·android-studio·android runtime
sinat_255487818 分钟前
为 System.out 编写我们自己的包装类
java·开发语言·算法
a8a3028 分钟前
Springboot中CommandLineRunner的用法以及执行顺序的控制
java·spring boot·spring
代码探秘者20 分钟前
【大模型应用】1.了解RAG
java·人工智能·python·spring
sevenlin23 分钟前
Spring Boot 经典九设计模式全览
java·spring boot·设计模式
Barkamin23 分钟前
快速排序非递归实现
java·算法·排序算法
crossoverJie25 分钟前
DeepWiki 优化实战:代码行号与确定性目录生成
后端·ai编程
salipopl27 分钟前
Spring Boot 集成 MyBatis 全面讲解
spring boot·后端·mybatis