【问题标题】:Error: Could not parse as expression, th:action错误:无法解析为表达式,th:action
【发布时间】:2019-03-22 05:01:00
【问题描述】:

我想用 Thymeleaf 和 Spring 发出 POST 请求。我的目标是从 HTML 接收选定的信息。但最初我只想在我从 th:action - "cidashboard/table" 按下以下链接的提交按钮时重定向我。

我的控制器:

   @GetMapping("cidashboard/filter/data")
    public String allDataForFilter(Model model) {
        model.addAttribute("projectsVariants", projectVariantService.findAllProjectsVariants());
        model.addAttribute("builds", buildService.findAllBuildFromDB());
        model.addAttribute("misraMessages", misraMessagesService.findAllMisraMessagesFromDb());

        return "test2";
    }

    @PostMapping("cidashboard/table")
    public String createTable() {
        return "test1";
    }

我的html页面:

<form th:action="@/cidashboard/table" method="post">
    <select class="form-control">
        <option  th:each = "projectVariant : ${projectsVariants}" th:selected="${projectVariant.getProjectVariantId()}"  th:text="${projectVariant.getProjectVariantName()}"></option>
    </select>
    <input type="submit" value="submit"/>
</form>

我收到了这个错误:

Could not parse as expression: "@/cidashboard/table" 

【问题讨论】:

  • 将其更改为@{/cidashboard/table}。您缺少括号。

标签: spring thymeleaf


【解决方案1】:

由于documentation,您必须将relative 路径包装在brackets 中。

<form th:action="@{/cidashboard/table}" method="post">

解析为

<form action="/cidashboard/table" method="post">

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2017-09-22
    • 1970-01-01
    • 2016-01-21
    • 2021-09-16
    • 1970-01-01
    • 1970-01-01
    • 2013-04-13
    • 2013-01-17
    相关资源
    最近更新 更多