Upload images using Spring Boot. Immediately after uploading, the image is not displayed on the HTML, but it is displayed when the screen is refreshed after waiting for about 30 seconds.
Image file-> / resource / static / images / File name (file name such as xxx-20200712151409.jpg)-> Store in DB
Create a folder (temporarily called images) directly under the root folder This time, images are created directly under the root folder called Ramen Kingdom.
Create a WebConfiguration class (assumed to be AdditionalResourceWebConfiguration)
@Configuration
public class AdditionalResourceWebConfiguration implements WebMvcConfigurer {
@Override
public void addResourceHandlers(ResourceHandlerRegistry registry) {
registry.addResourceHandler("/images/**").addResourceLocations("file:images/");
}
}
After that, just change the code that stored the images to images directly under the root folder. However, on HTML, you need to do the following:
<img th:src="@{'/images/' + ${picture.filepath}}"/>
Files that change dynamically like this time are not stored under static! !! !!
that's all. Thank you for reading to the end.