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

启动查看效果:

图标成功显示!

相关推荐
用户7508837061951 分钟前
循环依赖加 @Lazy 后异常漂移?Spring 三级缓存为什么没兜住?
后端
唐青枫1 分钟前
Java MyBatis 实战指南:XML 映射、动态 SQL 与数据访问层设计
java·mybatis
码语智行2 分钟前
MQTT 配置、依赖与使用说明
java·物联网·mt
_日拱一卒2 分钟前
LeetCode:39组合总和
java·算法·leetcode·职场和发展
铁皮饭盒3 分钟前
Bun 的三种并发"暗器":reusePort、Worker、spawn,能硬刚 Java 吗?
前端·javascript·后端
Nturmoils4 分钟前
从 MySQL 到 KingbaseES:Database、Schema、User 一次讲透
数据库·后端
郝学胜-神的一滴4 分钟前
力扣 662 :二叉树最大宽度
java·数据结构·c++·python·算法·leetcode·职场和发展
CodeSheep5 分钟前
宇树科技,即将上市!
前端·后端·程序员
仙俊红5 分钟前
反射到底解决什么问题?
java·开发语言
MacroZheng7 分钟前
这款DeepSeek V4终端编程神器,在GitHub上火了!
人工智能·后端·deepseek