进阶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 分钟前
51-限流算法详解
java·后端·架构
1candobetter4 分钟前
JAVA后端开发——多模块项目重命名体系解析
java·开发语言·intellij-idea
彭于晏Yan6 分钟前
Spring Boot + WebSocket 实现单聊已读未读(四)
spring boot·python·websocket
RainCity8 分钟前
Java Swing 自定义组件库分享(二)
java·笔记
彭于晏Yan8 分钟前
Spring Boot 整合 WebSocket + Redis 实现离线消息(三)
spring boot·redis·websocket
程序员老邢10 分钟前
【产品底稿 06】商助慧V1.2实战复盘:Milvus向量库重构+RAG仿写升级+前端SSE排版彻底修复
java·人工智能·经验分享·spring boot·ai·milvus
Bat U11 分钟前
JavaEE|多线程(四)
java·开发语言
阿丰资源12 分钟前
基于SpringBoot+MySQL的在线拍卖系统设计与实现(附源码)
spring boot·后端·mysql
Han.miracle13 分钟前
Spring Cloud + Nacos 环境切换与配置管理最佳实践
数据库·spring boot·spring cloud·maven
在屏幕前出油17 分钟前
08. ORM——快速开始
数据库·后端·python·sql·pycharm·orm