"Spring Boot 根路径映射到index.html - 打开/ 默认到index.html"\n\n在Spring Boot中,可以使用以下方法来将根路径(/)映射到index.html文件:\n\n1. 在src/main/resources/static目录下创建index.html文件。\n\n2. 在Spring Boot的主类上添加@Controller注解。\n\n3. 创建一个@RequestMapping注解,并将其值设置为“/”。\n\n4. 在方法中返回“index”。\n\n示例代码如下:\n\njava\n@Controller\npublic class HomeController {\n\n @RequestMapping("/")\n public String index() {\n return \"index\";\n }\n}\n\n\n这将使Spring Boot应用程序在启动时将根路径(/)映射到index.html文件,从而实现打开/ 默认到index.html的效果。

Spring Boot 根路径映射到index.html - 打开/ 默认到index.html

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

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