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

启动查看效果:

图标成功显示!

相关推荐
江畔柳前堤1 小时前
roLabelImg 详细安装教程
开发语言·人工智能·后端·云原生
白鸽(二般)2 小时前
MinIO Java Client API
java·开发语言
软萌萌的13 小时前
Java Spring Boot 修改yml配置&加载顺序规则
java·spring boot·python
陈随易3 小时前
moon,apt和yum之外linux系统命令安装新选择
前端·后端·程序员
IT小盘4 小时前
13-企业Prompt模板-角色任务约束与输出格式
java·前端·prompt
爱敲键盘的猴子4 小时前
Java并发编程 -- volatile
java·java并发
码事漫谈4 小时前
当单库日增 4.5TB,异构实时同步还能稳得住吗?
后端
plainGeekDev5 小时前
工厂模式 → Hilt
android·java·kotlin
plainGeekDev5 小时前
Application 单例 → Hilt Singleton
android·java·kotlin
888CC++6 小时前
C语言与C++的区别:从面向过程到面向对象
java·c语言·c++