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

启动查看效果:

图标成功显示!

相关推荐
松就是我9029814 分钟前
如何搭建一个 Agent 系统:方法论、理想形态与一次真实落地
后端
Layer16 分钟前
即时通讯系统的关键设计
后端·架构
java、iOS、Vue17 分钟前
Maven antrun vs Jenkins 脚本组装 deb的优缺点、适用场景
java·jenkins·maven
hudd66826 分钟前
JavaEE 初阶 - 多线程(初阶)
java·开发语言·java-ee
CarIise40 分钟前
Java实训阶段查漏补缺复习笔记2
java·linux·算法
Wang's Blog1 小时前
Java框架 SpringCloud 快速入门: Feign 的性能优化
java·spring cloud·性能优化
golang学习记1 小时前
rust开发,选VS Code还是RustRover?
开发语言·后端·rust
蛋蛋的就会顺顺的1 小时前
hot100——二叉树
java·数据结构·算法·leetcode·力扣
打工仔折腾 AI1 小时前
System Prompt 替代 Few-shot:用规则约束大模型输出的省钱实践
java·人工智能·python·spring·langchain·prompt·ai agent 实战
打工仔折腾 AI1 小时前
从零写一个CAD 05:以鼠标为中心的滚轮缩放,招法能复用但顺序不能反
开发语言·后端·python·性能优化·计算机外设·swift·ai agent 实战