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

启动查看效果:

图标成功显示!

相关推荐
小码编匠5 分钟前
C# 上位机开发怎么学?给自动化工程师的建议
后端·c#·.net
库森学长6 分钟前
面试官:发生OOM后,JVM还能运行吗?
jvm·后端·面试
转转技术团队8 分钟前
二奢仓店的静默打印代理实现
java·后端
蓝易云8 分钟前
CentOS 7上安装X virtual framebuffer (Xvfb) 的步骤以及如何解决无X服务器的问题
前端·后端·centos
钢铁男儿26 分钟前
C# 接口(什么是接口)
java·数据库·c#
丶小鱼丶39 分钟前
排序算法之【归并排序】
java·排序算法
上上迁42 分钟前
分布式生成 ID 策略的演进和最佳实践,含springBoot 实现(Java版本)
java·spring boot·分布式
永日4567042 分钟前
学习日记-spring-day42-7.7
java·学习·spring
秋千码途1 小时前
小架构step系列07:查找日志配置文件
spring boot·后端·架构
龙谷情Sinoam1 小时前
扩展若依@Excel注解,使其对字段的控制是否导出更加便捷
java