gpt4 book ai didi

Java Spring,Whitelabel 错误,我的第一个项目运行遇到问题

转载 作者:太空宇宙 更新时间:2023-11-04 13:12:15 27 4
gpt4 key购买 nike

我在使用 html 模板运行我的第一个 Java Spring 项目时遇到问题。我将模板放入 src/main/resources/templates 中。 Controller 方法调用成功。但模板没有被调用,而是出现了 Whitelabel 错误:

Whitelabel Error Page

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

Fri Nov 20 19:43:09 EST 2015
There was an unexpected error (type=Not Found, status=404).
No message available

有人知道我在这里做错了什么吗?如果我将 @ResponseBody 添加到 Controller ,它会将字符串打印到屏幕上,但我不知道如何让模板通过。谢谢。

MasterSpringMvcApplication.java

package masterSpringMvc;

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

@SpringBootApplication
public class MasterSpringMvcApplication {

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

HelloController.java

package masterSpringMvc.controllers;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

@Controller
@RequestMapping("/")
public class HelloController {


public String hello() {
System.out.println("HelloController called!");
return "resultPage";
}
}

结果页.html

<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org">
<head lang="en">
<meta charset="ISO-8859-1">
<title>Hello thymeleaf</title>
</head>
<body>
<span th:text="|Hello thymeleaf|">Chup Html</span>
</body>
</html>

构建.gradle

....
dependencies {
compile('org.springframework.boot:spring-boot-starter-web')
compile('org.springframework.boot:spring-boot-starter-thymeleaf')
testCompile('org.springframework.boot:spring-boot-starter-test')
}
....

最佳答案

@RequestMapping("/")添加到 Controller 方法。就你而言 -

    @RequestMapping("/")
public String hello() {
System.out.println("HelloController called!");
return "resultPage";
}

关于Java Spring,Whitelabel 错误,我的第一个项目运行遇到问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33849630/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com