在Spring Boot中,可以使用以下方法来将根路径(/)映射到index.html文件:

  1. 在src/main/resources/static目录下创建index.html文件。

  2. 在Spring Boot的主类上添加@Controller注解。

  3. 创建一个@RequestMapping注解,并将其值设置为“/”。

  4. 在方法中返回“index”。

示例代码如下:

@Controller
public class HomeController {

   @RequestMapping("/")
   public String index() {
      return "index";
   }
}

这将使Spring Boot应用程序在启动时将根路径(/)映射到index.html文件,从而实现打开/ 默认到index.html的效果。

spring root 打开 默认到indexhtml

原文地址: https://www.cveoy.top/t/topic/hfPN 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录