Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/304.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 百里香叶+;静态资源&x2B@应答器_Java_Spring Mvc_Thymeleaf - Fatal编程技术网

Java 百里香叶+;静态资源&x2B@应答器

Java 百里香叶+;静态资源&x2B@应答器,java,spring-mvc,thymeleaf,Java,Spring Mvc,Thymeleaf,在Spring Boot中,我得到了有史以来最简单的控制器,返回了我的视图名称: @Controller public class HelloController { @RequestMapping("/hello") public String hello() { return "helloworld.html"; } } 我的helloworld.html文件位于resources/static目录中: <html> <body&

在Spring Boot中,我得到了有史以来最简单的控制器,返回了我的视图名称:

@Controller
public class HelloController {

    @RequestMapping("/hello")
    public String hello() {
        return "helloworld.html";
    }
}
我的
helloworld.html
文件位于
resources/static
目录中:

<html>
<body>
Hello world!
</body>
</html>

一切都恢复正常,我在浏览器中看到“Hello world!”。但我知道,
@ResponseBody
注释将返回值作为响应的主体。那么,为什么它奇迹般地导致视图文件再次被找到呢?

我测试了您的代码,但我没有得到“helloworld”作为响应,而thymeleaf和html则放在static下。但是我被打印了字符串

“helloworld.html”,带有注释@ResponseBody


控制器方法返回一个字符串,在您的例子中,该字符串是误导性的“helloworld.html”

可能您没有重建项目?因为它绝对应该返回
helloworld.html
@Controller
public class HelloController {

    @RequestMapping("/hello")
    @ResponseBody
    public String hello() {
        return "helloworld.html";
    }
}