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

启动查看效果:

图标成功显示!

相关推荐
Soofjan4 分钟前
(二)数组和切片
后端
Java不加班26 分钟前
Nginx 核心实战指南:反向代理、负载均衡与动静分离
后端
子玖29 分钟前
微信扫码注册登录-基于网站应用
后端·微信·go
Assby30 分钟前
Java速通Go基础内容
后端
心在飞扬31 分钟前
LangGraph 基础知识
前端·后端
Java编程爱好者32 分钟前
MyBatis-mybatis入门与增删改查
后端
神奇小汤圆37 分钟前
并发编程进阶:volatile、内存屏障与 CPU 缓存机制详解
后端
神奇小汤圆1 小时前
Redis实现 IP 维度滑动窗口限流实践
后端
程序员清风1 小时前
小红书二面:Spring Boot的单例模式是如何实现的?
java·后端·面试
belhomme1 小时前
(面试题)Redis实现 IP 维度滑动窗口限流实践
java·面试