refactor(music-houduan): 优化文件上传和轮播图逻辑
- 修改 BannerServiceImpl 中的图片 URL 设置逻辑,保留原有的 /upload/images/... 格式 - 更新 FileServiceImpl 中的文件上传方法,返回文件的相对访问 URL 而非绝对物理路径
This commit is contained in:
@@ -74,7 +74,7 @@ public class BannerServiceImpl implements BannerService {
|
||||
// 创建轮播图实体
|
||||
Banner banner = new Banner();
|
||||
BeanUtils.copyProperties(bannerDTO, banner);
|
||||
banner.setImageUrl(imageUrl);
|
||||
banner.setImageUrl(imageUrl); // imageUrl已经是 /upload/images/... 格式
|
||||
banner.setStatus(banner.getStatus() != null ? banner.getStatus() : 1);
|
||||
|
||||
// 保存轮播图
|
||||
@@ -99,7 +99,7 @@ public class BannerServiceImpl implements BannerService {
|
||||
|
||||
// 上传新图片
|
||||
String imageUrl = fileService.uploadImage(image);
|
||||
banner.setImageUrl(imageUrl);
|
||||
banner.setImageUrl(imageUrl); // imageUrl已经是 /upload/images/... 格式
|
||||
}
|
||||
|
||||
// 更新轮播图信息
|
||||
|
||||
@@ -193,8 +193,8 @@ public class FileServiceImpl implements FileService {
|
||||
// 保存文件
|
||||
try {
|
||||
file.transferTo(targetFile);
|
||||
// 返回文件的绝对物理路径
|
||||
return targetFile.getAbsolutePath();
|
||||
// 返回文件的相对访问URL,并确保使用正斜杠
|
||||
return accessPath + directory + "/" + fileName;
|
||||
} catch (IOException e) {
|
||||
logger.error("上传文件失败", e);
|
||||
throw new BusinessException("上传文件失败");
|
||||
|
||||
Reference in New Issue
Block a user