简体   繁体   中英

How to append a thymeleaf variable in an <img > tag that has a src?

似乎无法为此找到正确的语法?

<img id='barcode' src="https://api.qrserver.com/v1/create-qr-code/?data="'+ ${var.membervar} + "'+&amp;size=100x100" alt="" title="HELLO" width="50" height="50" />

You should let Thymeleaf know you want to parse the src attribute by using th:src . Something like this would work ...

<img id='barcode' th:src="'https://api.qrserver.com/v1/create-qr-code/?data='+ ${var.membervar} + '&amp;size=100x100'" alt="" title="HELLO" width="50" height="50" />

But for the fully qualified URLs you should be using Thymeleaf Link Urls where proper encoding will be applied for all your query parameters. For example ...

<img id='barcode' th:src="@{https://api.qrserver.com/v1/create-qr-code/(data=${var.membervar},size='100x100')}" alt="" title="HELLO" width="50" height="50" />

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM