Spring Boot Controller返回语句创建循环视图路径

@Controller
@RequestMapping("front")
public class FrontendController {

    @GetMapping("/hello")
    public String hello(){
        System.out.println("porttest");

        return "hello";
    }
}

going tohttp://localhost:8080/front/hello gives whitelabel error and

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

如果我将返回值从“ hello”更改为其他任何值,那么我会收到带有其他消息的白色标签

No message available

为什么return语句的值这样做?

im trying to return the hello.html page to browser enter image description here

评论
  • cut
    cut 回复

    错误消息是对该问题的巨大暗示。

    我将做以下假设:

    1. You want to use hello.html as the view
    2. You want to use Thymeleaf as your view provider

    To achieve that, you need a registered ViewResolver that uses Thymeleaf. If you include spring-boot-starter-thymeleaf on the classpath, one will be automatically registered for you.

    Then, move hello.html from static to templates and it should work.