springboot can access static resources in the static folder under resources by default. We generally upload images to a folder under static
For example, images:
It can be used during the development stage, but it cannot be used when the project is packaged as a jar package. When running, it will report that the file path cannot be found. At this time, you need to configure a virtual path to specify a fixed address on the hard disk.
:
Here I set After the files are uploaded, they are saved to the images folder under the c drive. The access address is: http://localhost:8888/images/xxx.jpg
/images/** above represents the address of the server requesting images. For example: http://localhost:8888/images/xxx.jpg will be mapped to the local C:/images /xxx.jpg
Note: I obtained the rootSavePath in the configuration file in the above code, but did not use it. Instead, I wrote file:/c:/images myself, because using this variable directly will report an error. File must be added in front of the path.
About springboot vue, changing the server folder image access display issue
I recently used springboot vue to do it I started a project, which involves image display and modification functions.
1. Create a virtual path and be able to access the pictures in the folder
2. The front-end uses element's el-upload to upload pictures, and the back-end uses MultipartFile file to receive them and replace the original folder. The picture can be successfully replaced, and the local folder picture is indeed replaced successfully
3. After confirming that the local picture has changed, it is found that the page picture has not changed, and the refresh has not changed
1. Using the virtual path, the front-end can access the local image img1.jpg
2.Then Delete the local img1.jpg, put it in img2.jpg, and change the name to img1.jpg. In fact, it means that the img1 picture is modified but the name remains unchanged.
3. The result still displays the original img1 picture. Refreshing the page is the same, and you can only separate the picture path. Display and refresh the browser before the replaced image appears.
The above is the detailed content of How to use SpringBoot to configure virtualization paths for image display. For more information, please follow other related articles on the PHP Chinese website!