代码之家  ›  专栏  ›  技术社区  ›  Georgi Michev

百里香如何获取变量值

  •  0
  • Georgi Michev  · 技术社区  · 7 年前

    我正在尝试创建一个URL来完成变量

    我的模板是:

    <div th:if="${!user.isEmailValidated()}" class="div-block-13">
        <div class="email_confirmed">
            <a href="/email/send/${user.getToken()}">Your email is not confirmed!</a>
        </div>
    </div>
    

    我的控制器是:

    @GetMapping(value = "/email/send/{token}")
    public String sendEmail(@PathVariable(value = "token") String token, Model model) {
        return "sent-email";
    }
    

    我需要url…/email/send/变量值,但我得到-email/send/$%7buser.gettoken()%7d

    1 回复  |  直到 7 年前
        1
  •  1
  •   Cyril    7 年前

    表达式 ${user.getToken()} 不是胸腺素评估的,因为它在平原上 href 属性。使用 th:href 要能够使用thymeleaf表达式: <a th:href="@{'/email/send/' + ${user.getToken()}}">