如何在i18n Thymeleaf/Spring消息的一部分中定义链接?

如何在i18n Thymeleaf/Spring消息的一部分中定义链接?,spring,hyperlink,internationalization,thymeleaf,Spring,Hyperlink,Internationalization,Thymeleaf,使用Spring/Thymeleaf i18n,我想创建一个类似“Click here”的HTML段落消息,其中只有一个单词“here”的链接。最好的方法是什么 我尝试的方式看起来不太好,也会导致类似的中断: 在messages.properties文件中: error.generic.click=Click error.generic.here=here 在HTML文件中: <p th:text="#{error.generic.click}"></p>

使用Spring/Thymeleaf i18n,我想创建一个类似“Click here”的HTML段落消息,其中只有一个单词“here”的链接。最好的方法是什么

我尝试的方式看起来不太好,也会导致类似的中断:

在messages.properties文件中:

error.generic.click=Click
error.generic.here=here
在HTML文件中:

        <p th:text="#{error.generic.click}"></p><p><a th:text="#{error.generic.here}" th:href="@{/contact}"></a></p>


回答

我觉得你的方式还不错。如果您只想解决换行问题,请执行以下操作:

<p>
    <span th:text="#{error.generic.click}"></span>
    <a th:text="#{error.generic.here}" th:href="@{/contact}"></a>
</p>
具有以下消息。属性:

error.generic=Click <a href="/contact">here</a>
error.generic=单击

这种方法的缺点是你不能再使用th:href了。我不建议这样做。但是,如果不使用
th::
而只使用普通的html标记,这会很有帮助。所以我想提一提。

非常感谢您的全面回答
error.generic=Click <a href="/contact">here</a>