1.在springboot项目的resources目录下新建file-upload-prod.properties
##路径 mac是/ windows是 \\
file.imageUserFaceLocation=/Users/wl/project/foodie-dev/images/foodie/faces
2.在项目中新建类,引入配置类
@Component
@ConfigurationProperties(prefix = "file")
@PropertySource("classpath:file-upload-dev.properties")
@Data
public class FileUpload {
private String imageUserFaceLocation;
}
3.在Controller类中注入FileUpload,并调用方法
@RestController
@RequestMapping("userInfo")
public class CenterUserController extends BaseController {
@Autowired
private FileUpload fileUpload;
//定义头像的保存地址
String fileSpace = fileUpload.getImageUserFaceLocation();
}