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

启动查看效果:

图标成功显示!

相关推荐
Rain的Java大神之路36 分钟前
Spring AI 2.0 GA 深度复盘:Java 后端做 AI 的分水岭,到底画在哪?
java·后端·aigc
青石路1 小时前
不依赖 Spring,你会如何自实现 RabbitMQ 消息的消费(二)
后端·rabbitmq
Csvn1 小时前
Nginx 可观测性与工程化:指标、告警与发布回滚演练
后端·nginx
光泽雨1 小时前
IActionResult 是 ASP.NET Core Web API 中非常常用的一种控制器方法返回类型
后端·asp.net
如夏倾城2 小时前
进程状态模型详解:从三态、五态到 Linux 状态码映射
java·linux·服务器
唐老板3 小时前
前端和后端,转 AI 全栈怎么转
前端·后端
掘金安东尼3 小时前
中国移动 OAS 是什么:智能体开放服务空间、四项能力与「自研」说法的核实
人工智能·后端
小南家的青蛙3 小时前
JVM 参数调优实战指南
java·jvm
JuiceFS3 小时前
缓存命中率 99.96%,小文件数量减少 99.92%:启智机器人 JuiceFS 生产实践
人工智能·后端·机器人
程序员鱼皮3 小时前
Antigravity 保姆级实战教程,从 0 到 1 万字干货!
前端·后端·ai编程