【问题标题】:How can i add an absolute image url in thymeleaf?如何在百里香中添加绝对图片网址?
【发布时间】:2022-01-25 13:54:46
【问题描述】:
我怎样才能像在 html 中一样在 thymeleaf 中添加在线图片 url,例如:
<img src="http://blahblah.png">
我想动态添加这个“http://blahblah.png”,即我想在 src 中使用 controller 和 thymeleaf 从数据库中添加这个。
【问题讨论】:
标签:
java
spring-boot
model-view-controller
thymeleaf
【解决方案1】:
在您的控制器中,将 url 添加到模型中。
@Controller
public class ExampleController {
@GetMapping("page")
public String examplePage(Map<String, Object> model) {
model.put("url", "https://google.com");
return "page";
}
}
在您的页面上,使用th:src 设置值。
<img th:src="${url}" />