SpringBoot configure virtual path for the picture show

Preface: springboot default can access static resource static files in the resources folder, we generally will upload the images to a specified file in the static folder, such as images, you can use the development stage, but when the project labeled jar package can not be used run will be reported can not find the file path. This time you need to configure the virtual path used to specify a fixed address in the hard disk.

First we upload the configuration file in application.properties file paths, and visit the address:

 

# Resource mapping path / images / **, url to access the request path 
spring.mvc.static-path-pattern = / ImagesRF Royalty Free / **


# resource mapping addresses file: D: // imgs /, this is my picture path, modify the real path to your pictures stored spring.resources.static-locations = file: D: // imgs /
 

Pictures can be accessed through the path

http://localhost:8080/images/20190729.jpg

 

Guess you like

Origin www.cnblogs.com/whu-2017/p/11266484.html