generated from youfool-project/youfool-prj-springboot-template
修改保存目录为可配置
This commit is contained in:
parent
6503e8a5d9
commit
b63f3bd0e8
|
|
@ -1,34 +1,32 @@
|
|||
package com.chinaweal.youfool.course.controller;
|
||||
|
||||
import cn.dev33.satoken.stp.StpUtil;
|
||||
import com.baomidou.dynamic.datasource.annotation.DSTransactional;
|
||||
import com.baomidou.mybatisplus.core.metadata.IPage;
|
||||
import com.chinaweal.youfool.course.entity.Course;
|
||||
import com.chinaweal.youfool.course.entity.CourseVideo;
|
||||
import com.chinaweal.youfool.course.entity.CourseAttachment;
|
||||
import com.chinaweal.youfool.course.entity.CourseComment;
|
||||
import com.chinaweal.youfool.course.service.CourseService;
|
||||
import com.chinaweal.youfool.course.service.CourseVideoService;
|
||||
import com.chinaweal.youfool.course.entity.CourseVideo;
|
||||
import com.chinaweal.youfool.course.service.CourseAttachmentService;
|
||||
import com.chinaweal.youfool.course.service.CourseCommentService;
|
||||
import com.chinaweal.youfool.course.service.CourseService;
|
||||
import com.chinaweal.youfool.course.service.CourseVideoService;
|
||||
import com.chinaweal.youfool.framework.springboot.rest.BaseResultCode;
|
||||
import com.chinaweal.youfool.framework.springboot.rest.RestResult;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.stereotype.Controller;
|
||||
import org.springframework.ui.Model;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.PathVariable;
|
||||
import org.springframework.web.bind.annotation.RequestParam;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.RequestBody;
|
||||
import org.springframework.web.bind.annotation.ResponseBody;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
import org.springframework.web.servlet.support.ServletUriComponentsBuilder;
|
||||
import com.chinaweal.youfool.framework.springboot.rest.RestResult;
|
||||
import com.chinaweal.youfool.framework.springboot.rest.BaseResultCode;
|
||||
import com.baomidou.dynamic.datasource.annotation.DSTransactional;
|
||||
|
||||
import java.io.File;
|
||||
import java.nio.file.Path;
|
||||
import java.nio.file.Paths;
|
||||
import java.time.LocalDate;
|
||||
import java.time.LocalDateTime;
|
||||
import java.nio.file.Paths;
|
||||
import java.nio.file.Path;
|
||||
import java.util.UUID;
|
||||
|
||||
/**
|
||||
|
|
@ -37,6 +35,7 @@ import java.util.UUID;
|
|||
* @author lroyia
|
||||
* @since 2025/10/24
|
||||
**/
|
||||
@Slf4j
|
||||
@Controller
|
||||
public class PageController {
|
||||
|
||||
|
|
@ -52,6 +51,9 @@ public class PageController {
|
|||
@Autowired
|
||||
private CourseCommentService courseCommentService;
|
||||
|
||||
@Value("${file.savePath:}")
|
||||
private String fileSavePath;
|
||||
|
||||
/**
|
||||
* 登录页面
|
||||
*
|
||||
|
|
@ -313,10 +315,10 @@ public class PageController {
|
|||
saveUploadFile(attachment, courseId, "attachment");
|
||||
}
|
||||
|
||||
return RestResult.ok(courseId, "课程发布成功");
|
||||
return RestResult.ok(courseId);
|
||||
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
log.error("课程发布失败", e);
|
||||
return RestResult.error(BaseResultCode.BUSINESS_LOGIC_ERROR, "课程发布失败:" + e.getMessage());
|
||||
}
|
||||
}
|
||||
|
|
@ -344,9 +346,7 @@ public class PageController {
|
|||
String newFileName = UUID.randomUUID().toString() + "." + fileFormat;
|
||||
|
||||
// 创建上传目录
|
||||
String uploadDir = "../uploads/courses/" + LocalDate.now().getYear() + "/" +
|
||||
String.format("%02d", LocalDate.now().getMonthValue()) + "/" +
|
||||
String.format("%02d", LocalDate.now().getDayOfMonth());
|
||||
String uploadDir = fileSavePath + "/" + courseId;
|
||||
Path uploadPath = Paths.get(uploadDir);
|
||||
if (!uploadPath.toFile().exists()) {
|
||||
uploadPath.toFile().mkdirs();
|
||||
|
|
|
|||
|
|
@ -79,6 +79,9 @@ server:
|
|||
context-path: ${COURSE_CONTEXT_PATH:/course}
|
||||
port: ${COURSE_PORT:8080}
|
||||
|
||||
file:
|
||||
savePath: ${FILE_SAVE_PATH:../file}
|
||||
|
||||
# Sa-Token配置
|
||||
sa-token:
|
||||
# token名称 (同时也是cookie名称)
|
||||
|
|
|
|||
Loading…
Reference in New Issue