Spring boot image upload and display function example explanation
First, describe the problem. The spring boot uses the embedded tomcat, so it is not clear where the files are uploaded, and the spring boot loads all the static files into the classpath directory at startup, so I don't know where the uploaded files are relative to the application directory or how to write the access path, I'm really confused about the novice.
Later, I thought of the official example. I didn't expect that the official example found by myself at the beginning was too dependent on Baidu and Google. As a result, I found that only the official example could help, and it was a great help. I went directly to the password code
After reading the above code, you can understand the idea of accessing files in spring boot. The path when saving is
This path will be created on the local project root directory and does not apply to the directory in the deployment, so it is impossible to access HTTP in general. Therefore, it provides resourceloader, so that this class can load files in non application directories and then return
So you can read the file, so you need to write the GetFile method to display the image
If you don't know much about spring boot, you can refer to the following two articles.
Spring boot quick start tutorial
Spring boot Quick Start Guide