Timeline & & & exception

I need the image to be loaded into the html img tag using thymeleaf. The problem is that the image itself is derived from a url that takes two parameters.

Example:

 <img src="/products/images?categoryId=1&image=1" /> 

The problem is that the image parameter is generated dynamically and therefore I need to use the tyymeleaf expression there. So I tried something like this:

 <img th:src="@{'/products/images?categoryId=1&image=' + ${product.id}}" /> 

But when I run this, I get the following message:

 Exception parsing document: template="product-list", line 104 - column 59 

Which indicates the place where the '&' character is. Now I tried to use '& amp; "but then the url becomes something like

 /products/images?categoryId=1&amp;image=1 

Obviously this will not work.

So how can I make the correct link with two parameters using thymeleaf, then?

+6
source share
2 answers

It is easy to do timelapse. Do not concatenate lines and just use @{'/products/images'(categoryId=1, image= ${product.id})}

See the documentation.

+6
source

The way you avoid the ampersand & in any html, &amp; . In fact, you should always avoid ampersands in all html attributes, whether you use Thymeleaf or not.

See this question for more details and links: Am I encoding ampersands in <a href ...>?

+3
source

Source: https://habr.com/ru/post/986207/


All Articles