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

启动查看效果:

图标成功显示!

相关推荐
phltxy12 小时前
Redis 持久化机制
java·redis·git
IT_陈寒13 小时前
被JavaScript的隐式类型转换坑到怀疑人生,记录这次离谱经历
前端·人工智能·后端
Gerardisite13 小时前
企业微信客户管理系统实战:标签、分层与自动化流程搭建
java·python·机器人·自动化·企业微信
ch.ju13 小时前
Java程序设计(第3版)第三章——数组的定义方式
java·开发语言
wzl2026121313 小时前
流量浪费的底层原因:基于SpringBoot构建企微客户精细化运营系统
spring boot·后端·企业微信
楼田莉子13 小时前
Linux网络:多路转接IO
服务器·c++·后端·软件构建
Chloeis Syntax13 小时前
JavaEE学习日记(2)---文件操作和IO
java·笔记·学习·java-ee
无风听海13 小时前
OAuth 2.0 response_type完全指南
java·开发语言·oauth
Cyan_RA913 小时前
SpringMVC 数据格式化处理 详解
java·开发语言·spring·mvc·ssm·springmvc·数据格式化
SunnyDays101113 小时前
Java 实现 PDF 中文文本查找与高亮的四种方法
java·pdf·查找文字