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

启动查看效果:

图标成功显示!

相关推荐
八股文领域大手子3 分钟前
深入浅出 Redis:核心数据结构解析与应用场景Redis 数据结构
java·数据结构·数据库·人工智能·spring boot·redis·后端
尽兴-8 分钟前
常用 Git 命令详解
java·git·vscode·gitee
Thomas_YXQ25 分钟前
Unity3D 测试驱动开发(TDD)框架设计
java·开发语言·驱动开发·全文检索·unity3d·lucene·tdd
王有品30 分钟前
Spring MVC 模型数据绑定:addAttribute 与 put 方法详解
java·spring·mvc
ChengZUOZZZ30 分钟前
蓝桥杯题目:二维前缀和
java·算法·蓝桥杯
渊渟岳39 分钟前
为了掌握设计模式,开发了一款Markdown 文本编辑器软件(已开源)
java·设计模式
雾喔41 分钟前
库洛游戏一面+二面
java·开发语言·游戏
介si啥呀~3 小时前
解决splice改变原数组的BUG(拷贝数据)
java·前端·bug
Code哈哈笑3 小时前
Idea连接远程云服务器上的MySQL,开放云服务器端口
服务器·后端·mysql·spring