Spring Boot Custom Configuration Items
Configuration File
existFiles need configuration
for example:
=D:\\flies\\springboot\\
@ConfigurationProperties Annotation
Use Notes@ConfigurationProperties
Configure configuration items and entitiesBean
Related
Implement the association between configuration items and entity class fields and read configuration file data
import ; import ; import ; @Data @Component @ConfigurationProperties(prefix = "file") public class FileConfig { private String path; }
use
Get configuration information
FileConfig fileConfig = new FileConfig(); // File save directoryString filePath = ();
@PostMapping("/upload/") @ResponseBody public Response upload(MultipartFile file) { // Verify that there are files if(file == null || ()){ return ("Upload failed, please select file",400); } FileConfig fileConfig = new FileConfig(); // File save directory String filePath = (); // Verify folder File folder = new File(filePath); if (!()) { (); } // file name String fileName = () + (); filePath = filePath + fileName; File saveFile = new File(filePath); try { (saveFile); return ("Upload successful"); } catch (IOException e) { (); return ("Upload failed",50001); } }
Summarize
The above is personal experience. I hope you can give you a reference and I hope you can support me more.