簡體   English   中英

Thymeleaf Java模板引擎正在更改一些特殊字符

[英]Thymeleaf java template engine is changing some special characters

final Context ctx = new Context();
context.setVariable("data", data);
templateEngine.process(template, context).trim();

這里是進口:

import org.thymeleaf.TemplateEngine;
import org.thymeleaf.context.Context;

模板變量指向“ content_completed”。 其中content_completed是項目類路徑中存在的html文件。

該html文件的內容:

<html xmlns:th="http://www.thymeleaf.org" th:inline="text" th:remove="tag">
[[${data.fileName}]][[${T(abc.composer.NoteData).COMPLETED_NO_ERRORS}]]
</html>

其中NoteData是一個Java類

如果此data.fileName具有類似“ sample&.text”的名稱,則Thymeleaf模板引擎會將其更改為“ sample&amp..text”。

關於如何避免這種情況的任何想法?

我自己解決了。 解決方法如下:

<html xmlns:th="http://www.thymeleaf.org" th:inline="text" th:remove="tag">
<th:block th:utext="${data.fileName}"/>[[${T(abc.composer.NoteData).COMPLETED_NO_ERRORS}]]
</html>

Thymeleaf正在轉義文件名,以便瀏覽器不會將&解釋為特殊的HTML字符(用於HTML實體)。

因此,我認為答案是,這是對的。 當您在瀏覽器中查看HTML輸出時,它將按預期呈現。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM