【问题标题】: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 中使用 controllerthymeleaf 从数据库中添加这个

【问题讨论】:

标签: 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}" />

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2017-07-31
    • 2018-04-09
    • 2014-06-25
    • 2021-07-12
    • 1970-01-01
    • 2016-06-17
    • 2017-06-29
    相关资源
    最近更新 更多