Html Can';t地图<;img>;在春天的靴子里,百里香

Html Can';t地图<;img>;在春天的靴子里,百里香,html,image,spring-boot,Html,Image,Spring Boot,我寻找答案的时间太长了。我开始了一个简单的SpringBootMaven项目。我无法在html文件上显示任何img。我试着把图像放在不同的位置,比如模板和静态图像,但这些都不起作用。一切正常(hibernate、postgre、bootstrap、thymeleaf)只有图像是我无法显示的。正在寻求帮助:) 这被放置在index.html中 <img th:src="@{/images/pruff.png}" src="../images/pruff.png" class="i

我寻找答案的时间太长了。我开始了一个简单的SpringBootMaven项目。我无法在html文件上显示任何img。我试着把图像放在不同的位置,比如模板和静态图像,但这些都不起作用。一切正常(hibernate、postgre、bootstrap、thymeleaf)只有图像是我无法显示的。正在寻求帮助:)

这被放置在index.html中

<img th:src="@{/images/pruff.png}"
      src="../images/pruff.png" class="img-responsive"/>


Img位于/src/main/resources/static/images/pruff.png中,我认为没有必要使用th:src选项。您应该仅对Spring/Java输出使用th操作

编辑:可能尝试扩展WebMVCConfigureAdapter以配置静态资源位置

import org.springframework.context.annotation.Configuration; import org.springframework.web.servlet.config.annotation.EnableWebMvc; import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry; import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter; @Configuration @EnableWebMvc public class WebConfig extends WebMvcConfigurerAdapter { @Override public void addResourceHandlers(ResourceHandlerRegistry registry) { registry.addResourceHandler( "/webjars/**", "/img/**", "/css/**", "/js/**") .addResourceLocations( "classpath:/META-INF/resources/webjars/", "classpath:/static/img/", "classpath:/static/css/", "classpath:/static/js/"); } } 导入org.springframework.context.annotation.Configuration; 导入org.springframework.web.servlet.config.annotation.EnableWebMvc; 导入org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry; 导入org.springframework.web.servlet.config.annotation.WebMVCConfigureAdapter; @配置 @EnableWebMvc 公共类WebConfig扩展了WebMVCConfigureAdapter{ @凌驾 public void addResourceHandlers(ResourceHandlerRegistry注册表){ registry.addResourceHandler( “/webjars/**”, “/img/**”, “/css/**”, “/js/**”) .addResourceLocations( “类路径:/META-INF/resources/webjars/”, “类路径:/static/img/”, “类路径:/static/css/”, “类路径:/static/js/”; } } 然后使用th:src/th:href调用右文件,该文件应与以下内容一起使用:

 <img src="/images/pruff.png" class="img-responsive"/>

我创建了一个示例maven项目,因为它看起来像一个常见问题


我删除了th:preffix并尝试了不同的组合。网站上只显示了一个白色的小盒子,还是什么都没有/