进阶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 小时前
柔光屏平板怎么选?华为 MatePad Air Z 柔光版学
后端
程序猿DD3 小时前
OctaFuse 2.19.0:重做管理后台界面与交互,模型目录同步更新
后端
金銀銅鐵4 小时前
带您看懂字节码指令(一):一帧里有什么
java·后端·ai编程
码事漫谈5 小时前
Agent 测评是什么?大白话讲一讲
后端
皮皮林5515 小时前
在 IDEA 里斗个地主不过分吧!
后端
nice_lcj5205 小时前
【从零理解 Spring AI · 14】RAG 的四个环节:加载、切分、向量化、检索
java·spring boot·embedding·向量数据库·rag·spring ai·ai应用开发
SomeOtherTime6 小时前
Rust所有权(AI回答)
开发语言·后端·rust
程序员cxuan7 小时前
离谱,AI 大佬顺手搓了个 YouTube ,而我顺手给他搓了个中文插件
人工智能·后端·程序员
学长毕设7 小时前
基于springboot科创竞赛信息平台-附源码
java·spring boot·后端
深蓝AI8 小时前
Gemini Decisions API 来了:一次前向打分取代逐字解码,校准误差 0.0250 才是 agent 分支调用的真门槛
人工智能·后端