SpringBootThymeleaf无法返回html页面,即使在堆栈溢出和google上有许多不同的解决方案

rkkpypqq  于 2021-08-20  发布在  Java
关注(0)|答案(1)|浏览(350)

春回大地
循环视图路径[code]:将再次分派回当前处理程序url[/code]。检查您的viewresolver设置(提示:这可能是由于生成默认视图名称而导致的未指定视图。)
尝试访问本地主机时:端口/代码

intellij idea还提供
无法解析mvc视图“代码”
当我停留在“代码”上时
控制器类:

package platform;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;

@Controller
public class controller {

    @GetMapping("/code")
    public String returnCode(){
        return "code";
    }
}

html位于resources/templates/code.html;

<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org">
<head>
    <title>Code</title>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
</head>
<body>
    <pre id="code_snippet">
        code.com
    </pre>
</body>
</html>

主要方法:

package platform;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;

@SpringBootApplication
public class CodeSharingPlatform {

    public static void main(String[] args) {
        SpringApplication.run(CodeSharingPlatform.class, args);
    }
}

build.gradle:

plugins {
    id 'org.springframework.boot' version '2.3.3.RELEASE'
    id 'io.spring.dependency-management' version '1.0.11.RELEASE'
    id 'java'
}

apply plugin: 'io.spring.dependency-management'

sourceCompatibility = 11

repositories {
    mavenCentral()
}

sourceSets.main.resources.srcDirs = ["src/resources"]

dependencies {
    implementation 'org.springframework.boot:spring-boot-starter'
    implementation 'org.springframework.boot:spring-boot-starter-actuator'
    implementation 'org.springframework.boot:spring-boot-starter-thymeleaf'
    developmentOnly 'org.springframework.boot:spring-boot-devtools'
    compile("org.springframework.boot:spring-boot-starter-web")
}

我甚至还跟着教程上的https://spring.io/guides/gs/serving-web-content/
但由于某些原因,他们的方法不起作用。。。

ercv8c1e

ercv8c1e1#

我错过了thymeleaf中的一些库,我所要做的就是重新启动ide lol或重新同步gradle

相关问题