【问题标题】:Thymeleaf modelvariables not recognized correctly by Intellij when using fragments使用片段时 Intellij 无法正确识别 Thymeleaf 模型变量
【发布时间】:2019-06-12 06:21:32
【问题描述】:

我正在尝试使用 Spring-Boot 并希望使用 Thymeleaf 作为我的模板引擎。出于某种原因,当我想在百里香片段中使用模型变量时,代码完成无法正常工作。例如,我正在定义我的片段之一:

<div th:fragment="destThemeDiv(adminViewDTO)">

当我现在想在某个表达式中使用 adminViewDTO 时,它可以工作,但是当我想访问 adminViewDTO 的成员时,IntelliJ 无法识别它们并用红色下划线。例如,当我这样做时:

<th:block th:each="someObject: ${adminViewDTO.someObjects}">

然后 someObjects 被带下划线读取,这似乎很明显,因为 IntelliJ 无法自行推断类型参数,但是即使我在片段顶部提供类型提示,它仍然无法正常工作:

<!--@thymesVar id="adminViewDTO" type="test.view.AdminViewDTO"-->

有什么方法可以使这项工作正常进行吗?我真的没有找到其他人抱怨这个。

提前致谢

【问题讨论】:

    标签: java spring-boot intellij-idea thymeleaf


    【解决方案1】:

    我觉得我想通了。当我将类型提示直接放在使用表达式的块上方而不是将其插入页面顶部时,它就起作用了。

    像这样:

    <!--@thymesVar id="adminViewDTO" type="test.view.AdminViewDTO"-->
    <th:block th:each="someObject : ${adminViewDTO.someObjects}">
      <!--When using someObject in expression here, it will be recognized-->
    </th:block>
    

    【讨论】:

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