【问题标题】:IntelliJ don't recognize thymeleaf's variablesIntelliJ 无法识别 thymeleaf 的变量
【发布时间】:2019-12-17 13:18:01
【问题描述】:

IntelliJ 无法识别 Thymeleaf 文档中指定的所有变量是否正常?

我在我的 Spring Boot 应用程序项目中使用 Thymeleaf 引擎模板并使用 IntelliJ 作为 IDE,但似乎 IntelliJ 没有实现所有 THymeleaf 功能,或者我的 IDE 配置有问题,或者我不明白。

例如:

${param.q}

应该读取 GET 方法的 q 变量,但 IntelliJ 无法识别该变量。在运行应用程序时,它可以正常工作。

模板(param.q 带有红色下划线)

<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org">
<head>
    <title>Title</title>

</head>

<body>

<p th:text="${param.q}">Some text</p>

</body>
</html>

弹簧控制器

package com.drogago.todo.controllers;

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

@Controller
public class TestController {

    @RequestMapping(value = "/test", method = RequestMethod.GET)
    public String showIndex2() {
        return "index2";
    }
}

【问题讨论】:

  • 代码在编辑器中的样子如何?我已经检查了示例项目,它是looks like this。 “不认识”是什么意思?
  • 非常感谢您的检查。所以是配置的问题。在我的例子中,IntelliJ 检测到错误并用红色下划线。
  • 谢谢!我已经编辑了。
  • 你能用$代替#吗?

标签: spring-mvc intellij-idea thymeleaf


【解决方案1】:

我找到了解决方案。由于 IntelliJ 无法加载资源,出现问题。当在“添加框架支持”菜单中选择 Thymeleaf 时,有信息表明资源正在加载,但进程处于无限循环中。我已禁用同步并重新启动 IntelliJ。然后我在“文件”菜单中关闭了项目并再次运行它。最后,我重新导入项目(在 Maven 菜单中)。现在它可以正常工作了。

【讨论】:

    猜你喜欢
    • 2013-02-18
    • 2019-06-12
    • 2018-11-08
    • 2016-02-04
    • 1970-01-01
    • 2016-12-07
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多