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

启动查看效果:

图标成功显示!

相关推荐
李白的天不白6 分钟前
一个服务器可以搭建多个网站
java·tomcat
●VON6 分钟前
AtomGit Flutter鸿蒙客户端:共享组件
java·flutter·华为·harmonyos·鸿蒙
程序猿乐锅7 分钟前
【JAVASE | 第十七篇】Java 网络通信
java·开发语言
执于代码8 分钟前
Java交互打印的问题
java
星星电灯猴8 分钟前
全面解决Charles抓取HTTPS请求响应中文乱码问题的方法与技巧
后端·ios
我命由我1234520 分钟前
Windows 操作系统 - Windows 查看防火墙是否开启、Windows 查看防火墙放行端口
java·运维·开发语言·windows·java-ee·操作系统·运维开发
fly spider21 分钟前
Spring 原理总览:从启动到请求执行
java·数据库·spring
大大杰哥36 分钟前
SSeEmitter的基本使用和介绍
java·sse·通信
道友可好37 分钟前
写给 AI 的入职手册,AGENTS.md
前端·人工智能·后端
闪电悠米38 分钟前
黑马点评-Redis 消息队列-02_list_pubsub_limits
java·数据库·ide·redis·缓存·list·intellij-idea