I'm using Spring and Thymeleaf:
I have an image in the directory:
resources / image / telescope.png
When I open the posts.html (home) page, located at the address below, the image is displayed.
Code to call the image in posts.html (home):
<img src="resources/imagem/telescope.png">
But when I click on a home page link to call a service in the HomeController:
@RequestMapping(value = "/categoria/{link}", method = RequestMethod.GET)
public ModelAndView postByCategoria(@PathVariable("link") String link, ModelMap model) {
List<Postagem> postagems = postagemService.findByCategoria(link);
model.addAttribute("postagens", postagems);
return new ModelAndView("posts.html", model);
}
The above method returns a view to the posts.html page again, I can not load the image anymore what's happening?
On inspecting it it says that it can not load the src of the image that is mounted by Spring:
The image is not really at this address! It's still here:
resources / image / telescope.png
I do not understand why he created this concatenation for the src of the image!
In the configuration class I enabled everything on the resources page to load:
public class WebConfig extends WebMvcConfigurerAdapter {
@Override
public void addResourceHandlers(ResourceHandlerRegistry registry) {
registry.addResourceHandler("/resources/**").addResourceLocations("/resources/");
}
...
...