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

启动查看效果:

图标成功显示!

相关推荐
全速向光8 分钟前
手机玩我的世界Java版:FCL启动器下载使用指南
java·智能手机·游戏程序
pjj1985410 分钟前
Hadoop-python中使用大数据1
java·ide·eclipse
好好沉淀15 分钟前
巧用 Set 去重与复合键:高效统计分组内不重复元素的数量
java·spring boot·后端
步行cgn22 分钟前
Spring Environment 详解:Spring Boot 配置管理的核心接口
spring boot·python·spring
Wang's Blog23 分钟前
Java框架快速入门: Spring Security+OAuth2之工程结构与开发环境配置
java·spring·状态模式
FfHUCisI24 分钟前
Golang 函数调用的瞬间:栈帧、拷贝栈与逃逸分析
开发语言·后端·golang
Csvn26 分钟前
🐍 Day 12: 编码与字符集 — 告别乱码噩梦
后端·python
lzfshub28 分钟前
Open-DIS Python发送DIS实体状态PDU:实现坦克炮塔与主炮部件参数
java·网络·python·dis
魏 无羡30 分钟前
springboot 拦截器
java·spring boot·后端