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

启动查看效果:

图标成功显示!

相关推荐
咖啡八杯几秒前
【无标题】
java·后端·设计模式
mqiqe1 分钟前
面试题-MyBatis 面试篇
java·面试·mybatis
摇滚侠2 分钟前
SpringMVC 入门到实战 @RequestMapping 14-24
java·spring
云烟成雨TD4 分钟前
Spring AI Alibaba 1.x 系列【80】可观测集成
java·人工智能·spring
Filwaod33 分钟前
MCP 接入模式对比:Agent - Gateway - 业务项目 vs Agent - Adapter - 业务项目
java·agent·mcp
kuonyuma41 分钟前
MyBatis入门·注解操作
java·spring boot·mysql·spring·mybatis
码界索隆1 小时前
Python转Java系列:面向对象基础
java·开发语言·python
DIY源码阁1 小时前
JavaSwing酒店管理系统 - MySQL版
java·mysql·eclipse
不恋水的雨1 小时前
easyexcel快速填充大数据量不覆盖后面的行解决方式
java·excel·poi
Rain5091 小时前
1.3. Next.js与Nest.js在AI数据分析中的角色
前端·javascript·人工智能·后端·数据分析·node.js·ai编程