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

启动查看效果:

图标成功显示!

相关推荐
疯狂的程序猴12 分钟前
用 HBuilder 上架 iOS 应用时如何管理Bundle ID、证书与描述文件
后端
cat三三29 分钟前
java之异常
java·开发语言
浙江第二深情34 分钟前
前端性能优化终极指南
java·maven
ShaneD77138 分钟前
Redis 实战:从零手写分布式锁(误删问题与 Lua 脚本优化)
后端
我命由我1234538 分钟前
Python Flask 开发问题:ImportError: cannot import name ‘Markup‘ from ‘flask‘
开发语言·后端·python·学习·flask·学习方法·python3.11
無量41 分钟前
Java并发编程基础:从线程到锁
后端
养乐多07221 小时前
【Java】IO流
java
俊男无期1 小时前
超效率工作法
java·前端·数据库
小信啊啊1 小时前
Go语言数组与切片的区别
开发语言·后端·golang
中国胖子风清扬1 小时前
SpringAI和 Langchain4j等 AI 框架之间的差异和开发经验
java·数据库·人工智能·spring boot·spring cloud·ai·langchain