【问题标题】:how to map Spring controllers to their thymeleaf views(intellij14)如何将 Spring 控制器映射到它们的 thymeleaf 视图(intellij14)
【发布时间】:2014-12-18 16:36:50
【问题描述】:

我正在尝试配置 spring boot thymeleaf 和 intellij,并且在大多数情况下已经成功了,但我似乎无法将控制器与他们的视图链接起来,因为 intellij 烦人地一直显示以下消息,并且自动-完成系统不起作用:

Cannot Resolve 'varName'

我的控制器看起来像这样“main/java/..../controller.java”

@Controller
public class CardsController {

    @RequestMapping(value="/card/{id}",method = RequestMethod.GET)
    public String viewCardAction(@PathVariable("id") Card card,Model model){
        model.addAttribute("card",card);
        return "cards/view";
    }
}

这是我的模型视图“main/resources/cards/view/cards/view”:

<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org">
<head lang="en">
    <meta charset="UTF-8"/>
    <title th:text="${card.name}"></title> <!-- this line shows the message -->
</head>
<body>
    <div th:text="${card.name}"></div> <!-- this line shows the message -->
</body>
</html>

是 intelij 仍然无法解决这个问题,还是我缺少一些配置

注意:它可以工作和编译,只是想启用自动完成

【问题讨论】:

    标签: spring spring-mvc intellij-idea spring-boot thymeleaf


    【解决方案1】:

    看起来这是 Intellij 中的一个错误。

    这是 youtrack 链接: https://youtrack.jetbrains.com/issue/IDEA-132738

    它还没有得到 JetBrains 开发人员的太多关注,因此您可能想要添加您的 cmets 或在那里投票。

    【讨论】:

    • jetbrains 的人正在研究更好的弹簧靴支持。我希望这也能更好地支持自动配置的 thymeleaf 集成。它应该在 14.x 版本中。
    【解决方案2】:

    由于仍未解决,可能会有人通过搜索来到这里,所以在接受的答案中发布的链接中,赵新京提到了here is the workaround

    <!--/*--><!--@thymesVar id="loginFormBean" type="sample.system.login.LoginFormBean"--><!--*/-->
    <form id="formMain" class="form-horizontal" action="#" data-th-action="@{/login}" data-th-object="${loginFormBean}" method="post"> as thymeleaf comment, nothing be left in html output
    

    你也可以用它来指定集合,例如

    <!--/*--><!--@thymesVar id="names" type="List<String>"--><!--*/-->
    <!--/*--><!--@thymesVar id="name" type="String"--><!--*/-->
    <li th:each="name: ${names}" ... />
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-10-25
      • 2012-12-22
      • 2022-08-23
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多