'How can i add an absolute image url in thymeleaf?

how can I add an online image url in thymeleaf like we do in html eg:

<img src="http://blahblah.png">

I want to add this "http://blahblah.png" dynamically i.e. I want to add this from database using a controller and thymeleaf inside src.



Solution 1:[1]

In your controller, add the url to the model.

@Controller
public class ExampleController {

  @GetMapping("page")
  public String examplePage(Map<String, Object> model) {
    model.put("url", "https://google.com");
    return "page";
  }
}

On your page, set the value using th:src.

<img th:src="${url}" />

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Metroids