如何设置包含Thymeleaf&符号的URL?

vph*_*nyc 7 java spring thymeleaf

我有类似的东西:

Locale defaultLocale = Locale.getDefault();
final Context ctx = new Context(defaultLocale);
String url = getHost() + "/page?someId=" + some.getId() + "&someParam=" + Boolean.TRUE;
ctx.setVariable("url", url);

final String htmlContent = templateEngine.process("theHtmlPage", ctx);
Run Code Online (Sandbox Code Playgroud)

但是,当我查看生成的HTML进行打印时url,它会显示&amp而不是&在URL中显示.

有什么建议?

我尝试使用反引号来逃避Java代码中的&符号,但它也只是打印出来.环顾四周,但没有找到相关的内容.也试过了&

更新:好的,这不会破坏链接,但是如果没有它,Spring似乎没有将参数"someParam"解析为true.

渲染标签:

<span th:utext="${url}"></span>
Run Code Online (Sandbox Code Playgroud)

输出:

<span>http://localhost:8080/page?someId=1&amp;someParam=true</span>
Run Code Online (Sandbox Code Playgroud)

chr*_*ke- 2

Thymeleaf最近遇到了编码转义的问题,该问题已在 2.1.4 中修复。