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

启动查看效果:

图标成功显示!

相关推荐
小江的记录本1 分钟前
【分布式】分布式系统核心知识体系:CAP定理、BASE理论与核心挑战
java·前端·网络·分布式·后端·python·安全
ch.ju7 分钟前
Java程序设计(第3版)第二章——switch case break
java
曹牧7 分钟前
Spring MVC中使用HttpServletRequest和HttpServletResponse
java·spring·mvc
我命由我1234512 分钟前
Android 开发,getSystemService 警告信息:Must be one of: Context. POWER_SERVICE ...
android·java·java-ee·android studio·android jetpack·android-studio·android runtime
1candobetter13 分钟前
JAVA后端开发—— Maven 生命周期与 IDEA 中Maven 插件面板介绍
java·maven·intellij-idea
Fate_I_C13 分钟前
Kotlin 与 Java 互操作空安全处理策略
java·安全·kotlin
zopple15 分钟前
Laravel3.x经典特性回顾
android·java·数据库
一只小小Java19 分钟前
IDEA 的spring boot yaml没有叶子图标了
java·spring boot·intellij-idea
俺爱吃萝卜22 分钟前
Java 性能调优实战:从 JVM 内存模型到垃圾回收算法优化
java·jvm·算法
ic爱吃蓝莓23 分钟前
美团测开一面
java·开发语言