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

启动查看效果:

图标成功显示!

相关推荐
Nebula_g3 小时前
JavaSE项目实践:红包雨-线程池/线程
java·开发语言
小羊没烦恼!3 小时前
jQuery1.5的改进细节
java·服务器·开发语言·前端·c#
霸道流氓气质3 小时前
Prompt 版本控制与 A/B 测试实战:语义版本管理、一致性哈希分流与 Thompson Sampling 的 Java 生产级实现
java·prompt·哈希算法
嵌入式er4 小时前
影石系统组 一二面OC面经
java·开发语言
徐小黑ACG4 小时前
Golang 基础06 接口interface
开发语言·后端·golang
春涧草茶4 小时前
慢就是快12-12手动抛出异常
java·linux·前端
三小河4 小时前
从 Markdown 到 Generative UI:AI 如何从“生成答案”进化到“生成界面”?
前端·人工智能·后端
韩振方4 小时前
为什么加了 sudo,写配置文件还是 Permission denied?
后端
企业数字化笔记4 小时前
AI工具参数很多怎么办?预设、表单校验、危险参数与配置审计
java·spring boot·python·音视频
牛奔5 小时前
mise 管理多版本 Go 项目
开发语言·前端·chrome·后端·golang