因与&链接而导致的Thymeleaf解析错误

时间:2016-04-26 16:58:46

标签: spring url thymeleaf

我的链接:

<a data-pin-do="buttonPin" data-pin-color="white" data-pin-
count="beside" href="https://www.pinterest.com/pin/create/button/?

url=https%3A%2F%2Fwww.flickr.com%2Fphotos%2Fkentbrew%2F6851755809%2F
&media=https%3A%2F%2Ffarm8.staticflickr.com%2F7027%2F6851755809_df5b2051c9_z.jpg
&description=Next%20stop%3A%20Pinterest">
<img src="https://assets.pinterest.com/images/pidgets/pinit_fg_en_rect_white_20.png" />
</a>

目前,百里香认为&amp;在网址中应该跟一个&#39 ;;&#39;字符。

异常消息:

org.xml.sax.SAXParseException: The reference to entity "media" must end with the ';' delimiter.

有没有办法摆脱&amp;标志仍然有功能网址?或者有什么方法可以告诉他们要忽视&#39;和&amp;在网址上签名?

1 个答案:

答案 0 :(得分:1)

您应该使用实体&对您的网址进行编码,而不是&amp;,而不是href="www.myurl.com?param1=value&amp;param2=value"

@{...}

或者使用带有参数的Link URL Expression th:href="@{www.myurl.com(param1=${'value1'},param2=${'value2'})}" 构建它:

sql = "Select \"TESTDB\".\"CUSTOMER\".\"CUSTOMER_DETAIL_ID\" From \"TESTDB\".\"CUSTOMER\" WHERE \"TESTDB\".\"CUSTOMER\".\"CUSTOMER_DETAIL_ID\" in (?)";
PreparedStatement ps = conn.prepareStatement(sql);
    String input = "'8374859673849570','8374859673849557',...... more than 6000 characters"
ps.setString(1, input);
ps.executeQuery();

这不仅是一个Thymeleaf问题。您可以在此处找到详细说明:Do I really need to encode & as &amp;?