/**
*类上加@Component注解
*/
@Component
public class FileUpload {
//声明静态变量
private static String uploadPath;
//使用set方法注入
@Value("${uploadPath}")
public void setUploadPath(String uploadPath) {
this.uploadPath = uploadPath;
}
}
使用@Value 注解获取配置文件中的值注入到静态变量中
最新推荐文章于 2023-09-07 16:10:48 发布
本文介绍了一个使用Spring Boot实现文件上传的示例。通过在类上添加@Component注解,将FileUpload类作为组件注册到Spring容器中。使用@Value注解注入配置文件中的uploadPath属性,确保文件上传路径正确配置。
447

被折叠的 条评论
为什么被折叠?



