SpringBoot怎么访问页面?

.yml文件是这样配置

thymeleaf:
    prefix: classpath:/templates/
    suffix: .html
    mode: HTML5
    encoding: UTF-8
    servlet:
      content-type: text/html
    cache: false
    check-template-location: true

依赖我也在pom文件加了

<dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-thymeleaf</artifactId>
        </dependency>

index.html文件是放在resources目录下的templates下

@RequestMapping(value = "/index", method = RequestMethod.GET)
public String index(){
   return "index";
}

我这么访问 http://localhost:8080/admin/index
但是报错了,报了

Whitelabel Error Page

This application has no explicit mapping for /error, so you are seeing this as a fallback.

Fri Mar 13 11:55:25 CST 2020

There was an unexpected error (type=Internal Server Error, status=500).

Circular view path [index]: would dispatch back to the current handler URL [/admin/index] again. Check your ViewResolver setup! (Hint: This may be the result of an unspecified view, due to default view name generation.)

阅读 3.6k
3 个回答

依赖没有导入,指定下 spring-boot-starter-thymeleaf 的版本,然后重新 Reimport 一下试试

`<dependency>

<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-thymeleaf</artifactId>
<version>2.2.5.RELEASE</version>

</dependency>`

image.png

相同配置并没有复现问题…
spring-boot版本多少?

撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题