自定义mailto:使用Thymeleaf链接

时间:2017-08-15 14:31:58

标签: thymeleaf mailto

我正在使用Spring和Thymeleaf进行项目。 我有用户列表。我想使用mailto:

创建联系链接
<a href="mailto:name@email.com">

我正在显示这样的用户列表:

<tr th:each="users : ${users}">
    <td th:text="${users.id}"></td>
    <td th:text="${users.firstname}"></td>
    <td th:text="${users.lastname}"></td>
    <td th:text="${users.email}"></td>
</tr>

所以我想要实现的是,mailto适合每位新教授和他的电子邮件,而不是我手动编写。 我在想是否有可能写出这样的东西:

<td><a th:href = "mailto:${users.email}">

2 个答案:

答案 0 :(得分:7)

请尝试以下代码:

<td><a th:href="'mailto:' + ${users.email}">Send email </a></td>

答案 1 :(得分:0)

您可以使用链接语法使用额外的参数更安全地执行此操作:

<td><a th:href="@{mailto:{to}(to=${users.email})}">Send email </a></td>

这也允许您通过抄送、主题和正文:

<td><a th:href="@{mailto:{to}(to=${users.email},subject=${subj},body=${body})}">Send email </a></td>