Java 试一试百里香没有成功

Java 试一试百里香没有成功,java,spring-boot,gradle,thymeleaf,Java,Spring Boot,Gradle,Thymeleaf,我正在尝试使用thymeleaf,正如所有教程中所描述的那样,但不知何故,我的HTML没有被加载 以下是我的项目结构: 这些是依赖关系: dependencies { testCompile group: 'junit', name: 'junit', version: '4.12' compile("org.springframework.boot:spring-boot-starter-web:2.0.4.RELEASE") compile group: 'org.

我正在尝试使用thymeleaf,正如所有教程中所描述的那样,但不知何故,我的HTML没有被加载

以下是我的项目结构:

这些是依赖关系:

dependencies {
    testCompile group: 'junit', name: 'junit', version: '4.12'
    compile("org.springframework.boot:spring-boot-starter-web:2.0.4.RELEASE")
    compile group: 'org.thymeleaf', name: 'thymeleaf', version: '2.0.5'
}
它除了打印“Hello”消息之外什么也不做,但是,不使用resources文件夹中的HTML。我错过了什么

HelloController.java只有一个方法:

@RequestMapping("/hello")
  public String hello(Model model, @RequestParam(value="name", 
    required=false, defaultValue="World") String name) {
    model.addAttribute("name", name);
    return "hello " + name;
  }

main方法只是正常运行。

model.addAttribute使您可以在html文件中获取数据。 方法中的返回应该返回所需模板的名称。例如,您的hello.html

在hello.html中,放置如下内容:

<p th:text="${name}"></p>

您可能对控制器使用了不正确的注释

使用

@控制器

下面是一个例子:

@Controller
public class MyController {

@RequestMapping(value="/hello", method= RequestMethod.GET)
public String hello(Model model, @RequestParam(value="name", required=false, defaultValue="World") String name) {
  model.addAttribute("name", name);
  return "hello";
 }
}

您必须更改依赖项,而不是
org.thymeleaf
您需要以下依赖项:

compile group: 'org.springframework.boot', name: 'spring-boot-starter-thymeleaf', version: '1.5.1.RELEASE'
我希望这能解决你的问题


您能否提供所有相关代码或指向存储库的链接?这样,我们可以分析所有必要的部分,并进一步帮助您。提前感谢:)您能提供控制器的全部代码吗?您的应用程序类、html文件和整个控制器中有哪些代码?然后我们可以试着复制这个问题。实际上,我在html中有这一行,但它仍然不起作用。我将方法的返回改为只返回“hello”,但仍然没有任何结果。在网页上我只看到了“hello”字符串。@marti6addams您是否尝试过:
@RequestMapping(value=“/hello”,method=RequestMethod.GET)
@GetMapping(/hello”)
hmmm,我尝试过了,但得到了异常:2018-08-01 16:11:30.528错误10908---[nio-8080-exec-2]o.a.c.c.c.c.[/]具有路径[]的上下文中的[dispatcherServlet]引发异常[Circular view path[hello]:将再次调度回当前处理程序URL[/hello]。请检查ViewResolver设置!(提示:这可能是由于生成默认视图名而导致的未指定视图。)]由于根本原因,我重命名了我的html,但现在什么也没有显示。请注意,如果您使用的是其他人的内容,则必须包含正确的属性。
compile group: 'org.springframework.boot', name: 'spring-boot-starter-thymeleaf', version: '1.5.1.RELEASE'