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

启动查看效果:

图标成功显示!

相关推荐
海上彼尚2 分钟前
Go之路 - 7.go的函数
开发语言·后端·golang
计算机毕设指导63 分钟前
基于微信小程序的积分制零食自选平台【源码文末联系】
java·spring boot·mysql·微信小程序·小程序·tomcat·maven
神仙别闹5 分钟前
基于QT(C++)实现(图形界面)连连看
java·c++·qt
BioRunYiXue7 分钟前
双荧光素酶报告基因实验
java·运维·服务器·数据库·人工智能·数据挖掘·eclipse
Geoking.10 分钟前
深度理解 Java synchronized —— 从原理到实战
java·开发语言
martinzh18 分钟前
NL2SQL解决了?别闹了!大模型让你和数据库聊天背后的真相
后端
未来影子20 分钟前
Java领域构建Agent新杀入一匹黑马(agentscope-java)
java·开发语言·python
靓仔建20 分钟前
在asp.net web应用程序,老是访问同一个Handler1.ashx
后端·asp.net·一般处理程序
goxingman24 分钟前
实体类上关于时间字符串和时间字段转换涉及注解分析
java·开发语言