1、查资料得知:springboot项目默认是不允许直接访问template下的文件的,是受保护的。
所以想访问template下的html页面,我们可以配置视图解析器。
2、如果想要用视图去展示,应该要设置好视图展示页面,比如说用一个模板语言来接收返回的数据(thymeleaf或者freemarker等), 也可以用jsp接收,但是SpringBoot官方是不推荐用jsp的,而是建议使用thymeleaf作为模板语言,这里我以thymeleaf为例。
<dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-thymeleaf</artifactId> </dependency>
spring: thymeleaf: prefix: classpath: /templates # 访问template下的html文件需要配置模板,映射 cache: false # 开发时关闭缓存,不然没法看到实时页面
这里有两种方法,经过尝试都可以访问 index.html 页面
只不过,我这里没有返回数据,所以列表没有数据,但是返回到页面了