1、添加必要依赖 <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-thymeleaf</artifactId> </dependency> 2、配置资源文件 spring: thymeleaf: #定位模板的目录,即index文件目录 prefix: classpath:/static/ #给返回的页面添加后缀名 suffix: .html servlet: content-type: text/html mode: HTML cache: false encoding: utf-8 3、前端位置 static 文件夹放入 resources/static文件夹下index.html放入resources/static文件夹下 4、添加前端访问接口 @RestController public class HController { @GetMapping("home") public ModelAndView index(){ ModelAndView mv = new ModelAndView("index"); return mv; } } 5、运行