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

启动查看效果:

图标成功显示!

相关推荐
微风欲寻竹影11 小时前
Java数据结构——二叉树相关OJ题目详解
java·数据结构
微风欲寻竹影11 小时前
Java数据结构——二叉树(Binary Tree)详解
java·数据结构·算法
奋斗的小方11 小时前
Java进阶篇1-2:泛型
java·开发语言·windows
码语智行11 小时前
Codex 新手安装教程(完全小白版)
java·人工智能
z落落11 小时前
C# 多接口实现、重名成员、显式实现、接口继承+抽象类和接口区别
java·开发语言·c#
C137的本贾尼12 小时前
【实战】分析一张真实业务表的 InnoDB 存储结构
java·大数据·数据库
超梦dasgg12 小时前
亿级数据 不停服务平滑迁移(生产环境实战方案)
java·数据库
Zella折耳根12 小时前
Java 正则表达式实战:IP 地址匹配与替换全解析
java·tcp/ip·正则表达式
摇滚侠12 小时前
JavaWeb 全套教程 Filter 107-111
java·开发语言·servlet
YIN_尹12 小时前
【Linux系统编程】基础IO第一讲——系统文件IO
android·java·linux·c++