Home > Java > javaTutorial > body text

How to use SpringBoot to configure virtualization paths for image display

PHPz
Release: 2023-05-11 17:37:18
forward
1929 people have browsed it

Configure the virtualization path for image display

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.

1. First, we configure the file upload path and access address in the application.yml file

:

How to use SpringBoot to configure virtualization paths for image display

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

2. Configure the mapping of the virtual path

How to use SpringBoot to configure virtualization paths for image display

/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.

Configuring virtual path to access local image issues

About springboot vue, changing the server folder image access display issue

Question

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

For example

1. Using the virtual path, the front-endHow to use SpringBoot to configure virtualization paths for image display 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 resultHow to use SpringBoot to configure virtualization paths for image display 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!

Related labels:
source:yisu.com
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template