即使在Stack Overflow和Google Search上使用了许多不同的解决方案,Spring boot thy



Spring返回

循环视图路径〔code〕:将调度回当前处理程序URL[/code]。检查您的ViewResolver设置!(提示:这可能是由于默认视图名称,未指定视图的结果(

尝试访问localhost:port/code 时

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";
}
}

文件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")
}

我甚至遵循了教程*使用Spring MVC服务Web内容,但由于某种原因,他们的方法不起作用。。。

我在thymelaf中丢失了一些库。我所要做的就是重新启动我的IDE lol或重新同步Gradle。

相关内容

最新更新