Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/spring-boot/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Mongodb 如何在Mongo中保存HTML并在Thymeleaf中显示_Mongodb_Spring Boot_Thymeleaf - Fatal编程技术网

Mongodb 如何在Mongo中保存HTML并在Thymeleaf中显示

Mongodb 如何在Mongo中保存HTML并在Thymeleaf中显示,mongodb,spring-boot,thymeleaf,Mongodb,Spring Boot,Thymeleaf,我正在mongodb中存储博客帖子。文章可以有新行(存储为\n\r)和/或锚定标记 { "header" : "Some header", "body" : "The first paragraph.\n\rThe second paragraph\n\r<a href=\"www.example.com\" title=\"Example\">Example text</a>", "languageCode" : "DE" } { “头”:“某

我正在mongodb中存储博客帖子。文章可以有新行(存储为\n\r)和/或锚定标记

{
    "header" : "Some header",
    "body" : "The first paragraph.\n\rThe second paragraph\n\r<a href=\"www.example.com\" title=\"Example\">Example text</a>",
    "languageCode" : "DE"
}
{
“头”:“某个头”,
“正文”:“第一段。\n\r第二段\n\r”,
“语言代码”:“DE”
}
通过在my thymeleaf视图中执行此操作,我可以显示新行:

<p class="card-text" th:utext="${#strings.replace(#strings.escapeXml(blogEntry.blogPost.body),'&#10;','&lt;br&gt;')}"></p>

但是,定位标记显示为纯文本

如何将来自控制器的锚定标记格式化为指向其他站点的实际链接?

删除
#strings.escapeXml(…)
函数

注:

使用
th:text
意味着相关字符串中的任何HTML都将被转义,即
“…
…”
等字符串将被视为文本字符串。使用
th:utext
意味着字符串将保持不可缩放-因此字符串中的任何HTML标记(如
“…
…”
)将被视为HTML

但是,通过同时使用
#strings.escapeXml(…)
,您可以通过对正在处理的字符串进行转义来逆转
th:utext
的效果。在这种情况下,这不是你想要的


注意与使用
th:utext
相关的问题。例如,在将用户提供的(即不受信任的)输入保存到数据存储中之前,您可能希望以其他方式对其进行转义。

删除
#strings.escapeXml(…)
函数。没有这个对我有用。是的!它是这样工作的。如果你把它作为答案发布,我会把它标记为解决方案。谢谢