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

启动查看效果:

图标成功显示!

相关推荐
程序员-珍2 小时前
报错下载android sdk失败
android·java
糖果店的幽灵2 小时前
langgraph分支之 - 动态分支(Dynamic Branch)
java·前端·javascript·人工智能·langgraph
唐青枫3 小时前
Java Spring Security 实战详解:从登录认证到 JWT 权限控制
java
曹牧3 小时前
文档格式:OFD
java
豆角焖肉3 小时前
Maven进阶与搭建私服
java·maven
大不点wow4 小时前
Java序列化与反序列化:让对象走出JVM
java·开发语言·jvm
止语Lab4 小时前
好的 DX 不等于少写代码——三种语言的摩擦力设计课
后端
吃饱了得干活4 小时前
别再手动解析 LLM 输出了!LangChain 四种结构化输出方案对比
后端·python·langchain
噢,我明白了4 小时前
Java中日期和字符串的处理
java·开发语言·日期
程序员天天困4 小时前
Arthas trace 命令怎么用?一行定位最慢那行代码
jvm·后端