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

启动查看效果:

图标成功显示!

相关推荐
敢敢のwings19 分钟前
智元 GO-2 与 AgiBot-World 深度解读
开发语言·后端·golang
yaoxin52112327 分钟前
503. Java 反射 - 编写 ServiceFactory 类
java·开发语言·python
考虑考虑37 分钟前
Java三元表达式注意
java·后端·java ee
stark张宇1 小时前
Go语言runtime全景图:从编译到GC,带你彻底吃透Go的底层血脉
后端·go
IT_陈寒1 小时前
Redis的DEL命令居然没删干净数据?这个坑我爬了半天
前端·人工智能·后端
程序员小八7771 小时前
Java 快速转 Go
java·python·golang
职场的momo2 小时前
11个后端与AI岗位同时开放:Java、网关、推理优化怎么匹配
java·开发语言·人工智能
罗超驿2 小时前
SpringMVC 请求参数接收详解|单个参数、多参数、对象参数、@RequestParam参数重命名
java·后端·postman·javaee
__zRainy__2 小时前
Node系列 · ORM:Sequelize 简介
数据库·后端·node.js
AskHarries3 小时前
OpenClaw 如何查看历史对话和响应时间?
后端