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

启动查看效果:

图标成功显示!

相关推荐
郭小李5 小时前
mybatis 动态 sql
java·sql·mybatis
代龙涛5 小时前
WordPress Query 查询机制详解(WP_Query)
开发语言·后端·php·wordpress
瑞码空间5 小时前
JSP与Servlet核心开发与CRUD实战笔记
java·笔记·servlet·jsp
程序员cxuan5 小时前
不是,为啥这个模型突然就爆火了??
人工智能·后端·程序员
知守观5 小时前
技术考古:iBATIS 2.3.4 时代的持久层,是如何用 Map 玩转 307 个存储过程的?
java·后端·mybatis
程序员cxuan5 小时前
国产 GPU 能不能打,重点在软件栈
人工智能·后端·程序员
the局外人5 小时前
Python 中使用 SSE 实现大模型流式输出
后端·python·llm
苍何5 小时前
用 WorkBuddy + LibTV 做 AI 视频,干活有点猛啊!(附教程)
后端
苍何5 小时前
我的新书冲上京东热榜第一了!
后端
captain3766 小时前
MyBatis Plus(1)
java·服务器·mybatis