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

启动查看效果:

图标成功显示!

相关推荐
IT_陈寒7 分钟前
Vue的数组更新把我坑惨了
前端·人工智能·后端
栗子~~9 分钟前
java - logstash-logback-encoder 集成 demo
java·开发语言·logback
高晶12 分钟前
Android 智能语音开发新手入门实战
后端·程序员
励志不掉头发的内向程序员15 分钟前
鼠标点一下,图形是怎么画出来的?拆解 CAD 的 Action 状态机
后端·架构
hmb↑21 分钟前
高并发与高可用技术经验
java·spring
高晶22 分钟前
Android 机器视觉新手入门:从扫码到人脸实战
后端·程序员
写码跑山的老艾23 分钟前
基于 FSB 快速搭建 AI 客服:专家扩展与 Spring Boot 接入
后端
云边有个稻草人27 分钟前
从语句编写到执行追踪:金仓 SQL 编辑器实战指南
后端
楚识科技31 分钟前
XML配置OCR接入实战:自定义OCR模板从字段定义到API调用全流程
xml·java·ocr
code_slave(码畜)33 分钟前
微服务架构落地:消息队列架构设计(上篇)——异步解耦、削峰填谷,看懂业务事件流转本质
spring boot·spring cloud·微服务·云原生·架构