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

启动查看效果:

图标成功显示!

相关推荐
舒一笑10 分钟前
Ubuntu系统安装CodeX出现问题
linux·后端
华仔啊14 分钟前
Java 开发千万别给布尔变量加 is 前缀!很容易背锅
java
golang学习记1 小时前
GitLens 十大神技:彻底改变你在 VS Code 中的 Git 工作流
前端·后端·visual studio code
也些宝1 小时前
Java单例模式:饿汉、懒汉、DCL三种实现及最佳实践
java
一鹿高歌1 小时前
🔥内存炸了!背刺我的竟然是Redisson!!
后端
lizhongxuan1 小时前
AI 的底层思考
后端
Penge6662 小时前
解密 Kafka 与 RocketMQ 消费模型的核心之战
后端
Nyarlathotep01132 小时前
SpringBoot Starter的用法以及原理
java·spring boot
小码哥_常2 小时前
Spring Boot遇上Maven依赖冲突:打怪升级全攻略
后端