首页 > 解决方案 > IntelliJ 无法识别 thymeleaf 的变量

问题描述

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

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

例如:

${param.q}

应该读取方法的q变量,GET但 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";
    }
}

标签: spring-mvcintellij-ideathymeleaf

解决方案


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


推荐阅读