欢迎页 index
1.在静态资源路径下添加 index.html

直接访问项目地址

在配置yml文件中配置静态资源访问前缀
spring:
mvc:
static-path-pattern: /res/**
两种访问方式访问后404


静态资源前缀影响欢迎页访问(当前SpringBoot版本spring-boot-2.7.1.jar)
静态资源正常访问

2.controller中添加一个 /
@Controller
public class MyController {
@RequestMapping("/")
public String index(){
return "indexController";
}
}
pom.xml
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-thymeleaf</artifactId>
</dependency>
application.properties
spring.thymeleaf.prefix=classpath:/templates/
注意事项controller类上注解是@Controller不是@RestController,如果是@RestController返回得是字符串
访问结果

网站图标Favicon
favicon.ico 放在静态资源目录下即可

如果没有出现清理一下缓存后在访问
配置静态资源访问前缀

静态资源前缀影响Favicon 当前SpringBoot版本spring-boot-2.7.1.jar)
原创文章,作者:ItWorker,如若转载,请注明出处:https://blog.ytso.com/tech/pnotes/273634.html