进阶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 小时前
13-describe元数据输出
java·低代码·架构·状态模式
李昊哲小课1 小时前
SpringBoot4 云端咖啡站 阶段二:数据访问与分层架构
spring boot·架构
Profile排查笔记1 小时前
指纹浏览器怎么设置 IP?代理配置、检测与排错流程
前端·人工智能·后端·自动化
用户3721574261352 小时前
Java 设置 Word 文档编辑限制并允许指定区域编辑
java
宠友信息2 小时前
社区类源码开发实践中的仿小红书系统技术要点分析
java·spring boot·redis·mysql·uni-app·vue·内容运营
IT_陈寒2 小时前
SpringBoot自动配置失效?你可能漏了这个小开关
前端·人工智能·后端
用户3721574261352 小时前
Java 设置 PDF 表单域只读或扁平化
java
摇滚侠3 小时前
《SpringBoot 3:入门与应用实战》第 9 章 使用 WebMvc 开发应用 阅读笔记 1
spring boot·笔记·后端
用户8356290780513 小时前
使用 Python 在 Excel 中插入 OLE 对象
后端·python
程序员小八7773 小时前
Go 语言特性
开发语言·后端·golang