I'm trying to load a basic homepage just to try out Spring Boot and the images are not being loaded.
I've tried all sorts of different URL combinations to check whether the class path is wrong. Earlier I had an images folder within the static folder but this did not work either. I've removed adblock extensions, I've tried on both Firefox and Chrome browsers, I inspected the elements on the page for the image path and the response header. I have added no configuration to application.properties. I tried with and without the @EnableAutoConfiguration annotation as per https://docs.spring.io/spring-boot/docs/current/reference/htmlsingle/#getting-started-first-application-auto-configuration
The one thing I noticed was that the GET requests are all returning 200OK, as opposed to 404, and the type on the network tab is listed as text/html, whereas the Spring icon image used in the webpage title is listed as image/x-icon, but I don't know if that's the issue.
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
@Controller
@EnableAutoConfiguration
public class HomeController {
@GetMapping
public String home2() {
return "home2";
}
}
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:th="http://www.thymeleaf.org">
<head>
<meta charset="UTF-8">
<title>PuppR Home</title>
</head>
<body>
<h1>Homepage</h1>
<img src="jpx10.jpg"/>
<img src="/jpx10.jpg"/>
<img src="static/jpx10.jpg"/>
<img src="/static/jpx10.jpg"/>
<img src="../static/jpx10.jpg"/>
<img src="/../static/jpx10.jpg"/>
</body>
</html>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-thymeleaf</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-devtools</artifactId>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
I'm including links to images of my project structure as I don't have enough reputation to post images
https://i.imgur.com/gHdyS74.png
an image of the actual webpage generated with broken links, and the network console
试试这个, <img src="../static/jpx10.jpg" width="1000" th:src="@{/jpx10.jpg}"/>
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.