基于javaweb+mysql的springboot课程管理系统(java+springboot+vue+maven+mybatis+mysql)
运行环境
Java≥8、MySQL≥5.7、Node.js≥10
开发工具
后端:eclipse/idea/myeclipse/sts等均可配置运行
前端:WebStorm/VSCode/HBuilderX等均可
适用
课程设计,大作业,毕业设计,项目练习,学习演示等
功能说明
基于javaweb+mysql的SpringBoot课程管理系统(java+springboot+vue+maven+mybatis+mysql)
一、项目运行 环境配置:
Jdk1.8 + Tomcat8.5 + Mysql + HBuilderX(Webstorm也行)+ Eclispe(IntelliJ IDEA,Eclispe,MyEclispe,Sts都支持)。
项目技术:
Spring + SpringBoot+ mybatis + Maven + Vue 等等组成,B/S模式 + Maven管理等等。
@Value("${web.file-upload-path}")
private String path;
@Override
public ResultVO<FileInfoVO> uploadFile(MultipartFile file) {
try {
FileInfoVO fileInfoVO = FileHelper.save(path, file);
return new ResultVO<>(Constant.REQUEST_SUCCESS, "文件上传成功", fileInfoVO);
} catch (MyException myException){
logger.error("用于存放上传文件的文件夹不存在或创建失败,请检查路径是否有效", myException);
} catch (IOException ioException){
logger.error("文件复制时出错", ioException);
}
return new ResultVO<>(-1, "服务器错误,请联系网站管理员。");
}
@Override
public void downloadFile(String originName, String newName, HttpServletResponse response) {
InputStream inputStream = null;
OutputStream outputStream = null;
response.setContentType("application/x-msdownload");
try {
Resource resource = FileHelper.loadFileAsResource(path, originName);
if(resource == null)
return;
inputStream = resource.getInputStream();
//1.设置文件ContentType类型
response.setContentType("application/octet-stream;charset=UTF-8");
outputStream = response.getOutputStream();
//2.转码 UTF_8为传入的newName编码的格式 ISO_8859_1为浏览器默认编码
String convertName = new String(newName.getBytes(StandardCharsets.UTF_8), StandardCharsets.ISO_8859_1);
//3.设置 header Content-Disposition
response.setHeader("Content-Disposition", "attachment; filename=" + convertName);
int b = 0;
byte[] buffer = new byte[2048];
while (b != -1) {
b = inputStream.read(buffer);
if (b != -1) {
outputStream.write(buffer, 0, b);
}
}
} catch (IOException | MyException e) {
logger.error("文件下载时出错", e);
} finally {
try {
if(inputStream != null)
inputStream.close();
if (outputStream != null)
outputStream.close();
} catch (IOException e) {
logger.error("输入流或输出流关闭时出错!", e);
}
@RestController
@RequestMapping("/course_order")
public class CourseOrderController {
@Resource
private CourseOrderService orderService;
@PostMapping("/create")
public ResultVO<CourseOrderVO> createCourseOrder(@RequestParam Integer uid, @RequestParam Integer courseId){
return orderService.createCourseOrder(courseId,uid);
}
/**
* 根据uid查询用户所有的订单,
* 包括购买课程的订单 和 租用课程的订单
*/
@GetMapping("/uid/{uid}")
public List<CourseOrderVO> getCourseOrders(@PathVariable Integer uid){
return orderService.getCourseOrders(uid);
}
@GetMapping("/orderId/{orderId}")
public ResultVO<CourseOrderVO> getCourseOrderById(@PathVariable Integer orderId){
return orderService.getCourseOrderById(orderId);
}
@PostMapping("/update")
public ResultVO<CourseOrderVO> updateCourseOrderStatus(@RequestParam Integer orderId, @RequestParam Integer orderStatus){
return orderService.updateCourseOrder(orderId, orderStatus);
}
@PostMapping("/use_coupon")
public ResultVO<Boolean> useCoupon(@RequestBody CourseOrderVO orderVO, @RequestParam Integer couponId){
return orderService.useCoupon(orderVO, couponId);
}
@PostMapping("/cancel_coupon")
public ResultVO<Boolean> cancelCoupon(@RequestBody CourseOrderVO orderVO, @RequestParam Integer couponId){
return orderService.cancelCoupon(orderVO, couponId);
}
public ResultVO<FileInfoVO> uploadFile(MultipartFile file) {
try {
FileInfoVO fileInfoVO = FileHelper.save(path, file);
return new ResultVO<>(Constant.REQUEST_SUCCESS, "文件上传成功", fileInfoVO);
} catch (MyException myException){
logger.error("用于存放上传文件的文件夹不存在或创建失败,请检查路径是否有效", myException);
} catch (IOException ioException){
logger.error("文件复制时出错", ioException);
}
return new ResultVO<>(-1, "服务器错误,请联系网站管理员。");
}
@Override
public void downloadFile(String originName, String newName, HttpServletResponse response) {
InputStream inputStream = null;
OutputStream outputStream = null;
response.setContentType("application/x-msdownload");
try {
Resource resource = FileHelper.loadFileAsResource(path, originName);
if(resource == null)
return;
inputStream = resource.getInputStream();
//1.设置文件ContentType类型
response.setContentType("application/octet-stream;charset=UTF-8");
outputStream = response.getOutputStream();
//2.转码 UTF_8为传入的newName编码的格式 ISO_8859_1为浏览器默认编码
String convertName = new String(newName.getBytes(StandardCharsets.UTF_8), StandardCharsets.ISO_8859_1);
//3.设置 header Content-Disposition
response.setHeader("Content-Disposition", "attachment; filename=" + convertName);
int b = 0;
byte[] buffer = new byte[2048];
while (b != -1) {
b = inputStream.read(buffer);
if (b != -1) {
outputStream.write(buffer, 0, b);
}
}
} catch (IOException | MyException e) {
logger.error("文件下载时出错", e);
} finally {
try {
if(inputStream != null)
inputStream.close();
if (outputStream != null)
outputStream.close();
} catch (IOException e) {
logger.error("输入流或输出流关闭时出错!", e);
}
}
public ResultVO<FileInfoVO> uploadFile(MultipartFile file) {
try {
FileInfoVO fileInfoVO = FileHelper.save(path, file);
return new ResultVO<>(Constant.REQUEST_SUCCESS, "文件上传成功", fileInfoVO);
} catch (MyException myException){
logger.error("用于存放上传文件的文件夹不存在或创建失败,请检查路径是否有效", myException);
} catch (IOException ioException){
logger.error("文件复制时出错", ioException);
}
return new ResultVO<>(-1, "服务器错误,请联系网站管理员。");
}
@Override
public void downloadFile(String originName, String newName, HttpServletResponse response) {
InputStream inputStream = null;
OutputStream outputStream = null;
response.setContentType("application/x-msdownload");
try {
Resource resource = FileHelper.loadFileAsResource(path, originName);
if(resource == null)
return;
inputStream = resource.getInputStream();
//1.设置文件ContentType类型
response.setContentType("application/octet-stream;charset=UTF-8");
outputStream = response.getOutputStream();
//2.转码 UTF_8为传入的newName编码的格式 ISO_8859_1为浏览器默认编码
String convertName = new String(newName.getBytes(StandardCharsets.UTF_8), StandardCharsets.ISO_8859_1);
//3.设置 header Content-Disposition
response.setHeader("Content-Disposition", "attachment; filename=" + convertName);
int b = 0;
byte[] buffer = new byte[2048];
while (b != -1) {
b = inputStream.read(buffer);
if (b != -1) {
outputStream.write(buffer, 0, b);
}
}
} catch (IOException | MyException e) {
logger.error("文件下载时出错", e);
} finally {
try {
if(inputStream != null)
inputStream.close();
}
/**
* 教师修改测试信息
* @param courseTestDTO
* @return
*/
@PostMapping("/testFix")
ResultVO<CourseTestVO> fixTest(@RequestBody CourseTestDTO courseTestDTO) {
return courseTestService.fixTest(courseTestDTO);
}
/**
* 教师删除某个测试
* @param courseTestDTO
* @return
*/
@PostMapping("/testDelete")
ResultVO deleteQuestion(@RequestBody CourseTestDTO courseTestDTO) {
return courseTestService.deleteTest(courseTestDTO);
}
/**
* 老师获得自己创建的全部测试
* @param teacherId
* @return
*/
@GetMapping("/testGet/teacher/{teacherId}")
ResultVO<List<CourseTestVO>> getTestsByTeacherId(@PathVariable int teacherId) {
return courseTestService.getTestsByTeacherId(teacherId);
}
/**
* 学生查询一个课程的全部测试,需要返回测试成绩
*
* @param courseId
* @param userId
* @return
*/
@GetMapping("/testGet/course")
ResultVO<List<CourseTestVO>> getTestsByCourseId(@RequestParam int courseId, @RequestParam int userId) {
return courseTestService.getTestsByCourseId(courseId, userId);
}
/**
* 老师查询一个课程的全部测试
@Service
public class FileServiceImpl implements FileService {
private static final Logger logger = LoggerFactory.getLogger(FileServiceImpl.class);
@Value("${web.file-upload-path}")
private String path;
@Override
public ResultVO<FileInfoVO> uploadFile(MultipartFile file) {
try {
FileInfoVO fileInfoVO = FileHelper.save(path, file);
return new ResultVO<>(Constant.REQUEST_SUCCESS, "文件上传成功", fileInfoVO);
} catch (MyException myException){
logger.error("用于存放上传文件的文件夹不存在或创建失败,请检查路径是否有效", myException);
} catch (IOException ioException){
logger.error("文件复制时出错", ioException);
}
return new ResultVO<>(-1, "服务器错误,请联系网站管理员。");
}
@RestController
@RequestMapping("/course")
public class CourseController {
@Resource
private CourseService courseService;
/**
* 查询单一课程
* @param uid 用户id
* @param courseId 课程id
*/
@GetMapping("/{courseId}")
public CourseVO getCourseById(@RequestParam(required = false, defaultValue = "") Integer uid, @PathVariable Integer courseId) {
return courseService.getCourse(courseId, uid);
}
/**
* 获取课程列表
* 如果带参数uid,则需要判断该用户是否购买过课程
* 如果带参数key,则根据关键字返回分页查询结果
* @param uid 用户id
* @param key 关键字
*/
@GetMapping("/all/{page}")
public PageInfo<CourseVO> getCoursesByKey(@RequestParam(required = false, defaultValue = "") Integer uid,
@RequestParam(required = false, defaultValue = "") String key,
@PathVariable Integer page) {
return courseService.getCourses(page, Constant.COURSE_PAGE_SIZE, uid, key);
}
/**
* 根据分类标签,获取课程列表
* 如果带参数uid,则需要判断该用户是否购买过课程、该用户是否为课程的教师
* @param uid 用户id
* @param type 课程类别
*/
@RestController
@RequestMapping("/vip")
public class VipController {
@Autowired
VipService vipService;
/**
* 用户查看各种vip的价格
* @return
*/
@ResponseBody
@GetMapping("/price")
public ResultVO<List<VipInfoVO>> getVipPriceInfo(){
return vipService.getVipPriceInfo();
}
/**
* 用户购买vip
* @param vipChargeDTO
* @return
*/
@PostMapping("/get")
public ResultVO<VipChargeVO> chargeVip(@RequestBody VipChargeDTO vipChargeDTO){
return vipService.getVip(vipChargeDTO);
}
}
@RestController
* 学生查询测试的题目,
* 若已做,则返回每题成绩,答案,解析
* 若未做,则仅返回题目
* @param testId
* @param userId
* @return
*/
@GetMapping("/questionGet/test")
ResultVO<List<CourseQuestionVO>> getQuestionsByTestId(@RequestParam int testId, @RequestParam int userId) {
return courseTestService.getQuestionsByTestId(testId, userId);
}
/**
* 老师查询测试的题目
* 返回每题的全部信息
* @param testId
* @return
*/
@GetMapping("/questionGet/test/{testId}")
ResultVO<List<CourseQuestionVO>> getQuestionsByTestId(@PathVariable int testId) {
return courseTestService.getQuestionsByTestId(testId);
}
/**
* 教师为一门测试添加题目
* @param courseTestQuestionAddDTO
* @return
*/
@PostMapping("/testAddQuestion")
ResultVO addTestQuestion(@RequestBody CourseTestQuestionAddDTO courseTestQuestionAddDTO) {
return courseTestService.addTestQuestion(courseTestQuestionAddDTO);
}
/**
* 教师为一门测试删除题目
* @param courseTestQuestionDeleteDTO
* @return
*/
@PostMapping("/testDeleteQuestion")
ResultVO deleteTestQuestion(@RequestBody CourseTestQuestionDeleteDTO courseTestQuestionDeleteDTO) {
return courseTestService.deleteTestQuestion(courseTestQuestionDeleteDTO);
}
/**
@RestController
@RequestMapping("/file")
public class FileController {
@Resource
FileService fileService;
@PostMapping("/upload")
public ResultVO<FileInfoVO> upload(@RequestParam("file") MultipartFile file) {
return fileService.uploadFile(file);
}
@GetMapping("/download/{originName:.+}")
public void download(@PathVariable String originName, @RequestParam String newName, HttpServletResponse response) {
fileService.downloadFile(originName, newName, response);
}
}
@RestController
@RequestMapping("/recharge")
public class RechargeController {
@Resource
RechargeService rechargeService;
@PostMapping("")
public ResultVO<RechargeOrderVO> recharge(@RequestBody RechargeOrderVO rechargeOrderVO){
return rechargeService.rechargeAccount(rechargeOrderVO);
}
}
/**
* 教师为一门测试删除题目
* @param courseTestQuestionDeleteDTO
* @return
*/
@PostMapping("/testDeleteQuestion")
ResultVO deleteTestQuestion(@RequestBody CourseTestQuestionDeleteDTO courseTestQuestionDeleteDTO) {
return courseTestService.deleteTestQuestion(courseTestQuestionDeleteDTO);
}
/**
* 学生完成一门测试
* @param courseTestFinishDTO
* @return
*/
@PostMapping("/testAnswerCommit")
ResultVO finishTest(@RequestBody CourseTestFinishDTO courseTestFinishDTO) {
return courseTestService.finishTest(courseTestFinishDTO);
}
/**
* 教师创建一门测试
* @param courseTestDTO
* @return
*/
@PostMapping("/testCreate")
ResultVO<CourseTestVO> createTest(@RequestBody CourseTestDTO courseTestDTO) {
return courseTestService.createTest(courseTestDTO);
}
/**
* 教师修改测试信息
* @param courseTestDTO
* @return
*/
@PostMapping("/testFix")
ResultVO<CourseTestVO> fixTest(@RequestBody CourseTestDTO courseTestDTO) {
return courseTestService.fixTest(courseTestDTO);
}
/**
* 教师删除某个测试
* @param courseTestDTO
* @return
* @param uid 用户id
* @param key 关键字
*/
@GetMapping("/all/{page}")
public PageInfo<CourseVO> getCoursesByKey(@RequestParam(required = false, defaultValue = "") Integer uid,
@RequestParam(required = false, defaultValue = "") String key,
@PathVariable Integer page) {
return courseService.getCourses(page, Constant.COURSE_PAGE_SIZE, uid, key);
}
/**
* 根据分类标签,获取课程列表
* 如果带参数uid,则需要判断该用户是否购买过课程、该用户是否为课程的教师
* @param uid 用户id
* @param type 课程类别
*/
@GetMapping("/type/{page}")
public PageInfo<CourseVO> getCoursesByType(@RequestParam(required = false, defaultValue = "") Integer uid,
@RequestParam String type,
@PathVariable Integer page) {
return courseService.getCoursesByType(page, Constant.COURSE_PAGE_SIZE, uid, type);
}
/**
* 分页获取热门课程列表
* @param page 页码数
*/
@GetMapping("/hot/{page}")
public PageInfo<CourseVO> getHotCourses(@PathVariable Integer page, Integer uid) {
return courseService.getHotCourses(page, Constant.COURSE_PAGE_SIZE,uid);
}
/**
* 获取用户拥有的课程列表
* @param sid 学生id
*/
@GetMapping("/sid/{sid}")
public List<CourseVO> getOwnedCourses(@PathVariable Integer sid) {
return courseService.getOwnedCourses(sid);
}
/**
* 获取教师可管理的课程列表
* @param tid 教师id
*/
@GetMapping("/tid/{tid}")
public List<CourseVO> getManageableCourses(@PathVariable Integer tid) {
return courseService.getManageableCourses(tid);
}
* @param courseTestDTO
* @return
*/
@PostMapping("/testDelete")
ResultVO deleteQuestion(@RequestBody CourseTestDTO courseTestDTO) {
return courseTestService.deleteTest(courseTestDTO);
}
/**
* 老师获得自己创建的全部测试
* @param teacherId
* @return
*/
@GetMapping("/testGet/teacher/{teacherId}")
ResultVO<List<CourseTestVO>> getTestsByTeacherId(@PathVariable int teacherId) {
return courseTestService.getTestsByTeacherId(teacherId);
}
/**
* 学生查询一个课程的全部测试,需要返回测试成绩
*
* @param courseId
* @param userId
* @return
*/
@GetMapping("/testGet/course")
ResultVO<List<CourseTestVO>> getTestsByCourseId(@RequestParam int courseId, @RequestParam int userId) {
return courseTestService.getTestsByCourseId(courseId, userId);
}
/**
* 老师查询一个课程的全部测试
*
* @param courseId
* @return
*/
@GetMapping("/testGet/course/{courseId}")
ResultVO<List<CourseTestVO>> getTestsByCourseId(@PathVariable int courseId) {
return courseTestService.getTestsByCourseId(courseId);
}
}
* @param uid 用户id
* @param courseId 课程id
*/
@GetMapping("/{courseId}")
public CourseVO getCourseById(@RequestParam(required = false, defaultValue = "") Integer uid, @PathVariable Integer courseId) {
return courseService.getCourse(courseId, uid);
}
/**
* 获取课程列表
* 如果带参数uid,则需要判断该用户是否购买过课程
* 如果带参数key,则根据关键字返回分页查询结果
* @param uid 用户id
* @param key 关键字
*/
@GetMapping("/all/{page}")
public PageInfo<CourseVO> getCoursesByKey(@RequestParam(required = false, defaultValue = "") Integer uid,
@RequestParam(required = false, defaultValue = "") String key,
@PathVariable Integer page) {
return courseService.getCourses(page, Constant.COURSE_PAGE_SIZE, uid, key);
}
/**
* 根据分类标签,获取课程列表
* 如果带参数uid,则需要判断该用户是否购买过课程、该用户是否为课程的教师
* @param uid 用户id
* @param type 课程类别
*/
@GetMapping("/type/{page}")
public PageInfo<CourseVO> getCoursesByType(@RequestParam(required = false, defaultValue = "") Integer uid,
@RequestParam String type,
@PathVariable Integer page) {
return courseService.getCoursesByType(page, Constant.COURSE_PAGE_SIZE, uid, type);
}
/**
* 分页获取热门课程列表
* @param page 页码数
*/
@GetMapping("/hot/{page}")
public PageInfo<CourseVO> getHotCourses(@PathVariable Integer page, Integer uid) {
return courseService.getHotCourses(page, Constant.COURSE_PAGE_SIZE,uid);
}
/**
* 获取用户拥有的课程列表
* @param sid 学生id
*/
@GetMapping("/sid/{sid}")
public List<CourseVO> getOwnedCourses(@PathVariable Integer sid) {
return courseService.getOwnedCourses(sid);
}
/**
@Resource
private CourseWareService courseWareService;
/**
* 获取单个课件的信息
* @param uid 用户id
* @param courseWareId 课件id
*/
@GetMapping("/{courseWareId}")
public CourseWareVO getCourseWare(@RequestParam(required = false, defaultValue = "") Integer uid,
@PathVariable Integer courseWareId) {
return courseWareService.getCourseWare(uid, courseWareId);
}
/**
* 获取课件列表
* 如果带参数uid,则需要判断该用户是否购买过课程
* @param uid 用户id
* @param courseId 课程id
*/
@GetMapping("/course/{courseId}")
public List<CourseWareVO> getCourseWares(@RequestParam(required = false, defaultValue = "") Integer uid,
@PathVariable Integer courseId) {
return courseWareService.getAllCourseWare(uid, courseId);
}
/**
* 教师创建课件
* @param courseWare 课件VO
*/
@PostMapping("/create")
public ResultVO<CourseWareVO> createCourseWare(@RequestBody CourseWareVO courseWare){
return courseWareService.createCourseWare(courseWare);
}
/**
* 教师更新课件
* @param courseWare 课件VO
*/
@PostMapping("/update")
public ResultVO<CourseWareVO> updateCourseWare(@RequestBody CourseWareVO courseWare){
return courseWareService.updateCourseWare(courseWare);
}
* 根据uid查询用户所有的订单,
* 包括购买课程的订单 和 租用课程的订单
*/
@GetMapping("/uid/{uid}")
public List<CourseOrderVO> getCourseOrders(@PathVariable Integer uid){
return orderService.getCourseOrders(uid);
}
@GetMapping("/orderId/{orderId}")
public ResultVO<CourseOrderVO> getCourseOrderById(@PathVariable Integer orderId){
return orderService.getCourseOrderById(orderId);
}
@PostMapping("/update")
public ResultVO<CourseOrderVO> updateCourseOrderStatus(@RequestParam Integer orderId, @RequestParam Integer orderStatus){
return orderService.updateCourseOrder(orderId, orderStatus);
}
@PostMapping("/use_coupon")
public ResultVO<Boolean> useCoupon(@RequestBody CourseOrderVO orderVO, @RequestParam Integer couponId){
return orderService.useCoupon(orderVO, couponId);
}
@PostMapping("/cancel_coupon")
public ResultVO<Boolean> cancelCoupon(@RequestBody CourseOrderVO orderVO, @RequestParam Integer couponId){
return orderService.cancelCoupon(orderVO, couponId);
}
@PostMapping("/pay/{orderId}")
public ResultVO<Boolean> payOrder(@PathVariable Integer orderId){
return orderService.payOrder(orderId);
}
/**
* 创建课程租用订单
* @param orderRentDTO
* @return
*/
@PostMapping("/rent")
public ResultVO<CourseOrderVO> createCourseRentOrder(@RequestBody OrderRentDTO orderRentDTO){
return orderService.createCourseRentOrder(orderRentDTO);
}
}
}
@GetMapping("/orderId/{orderId}")
public ResultVO<CourseOrderVO> getCourseOrderById(@PathVariable Integer orderId){
return orderService.getCourseOrderById(orderId);
}
@PostMapping("/update")
public ResultVO<CourseOrderVO> updateCourseOrderStatus(@RequestParam Integer orderId, @RequestParam Integer orderStatus){
return orderService.updateCourseOrder(orderId, orderStatus);
}
@PostMapping("/use_coupon")
public ResultVO<Boolean> useCoupon(@RequestBody CourseOrderVO orderVO, @RequestParam Integer couponId){
return orderService.useCoupon(orderVO, couponId);
}
@PostMapping("/cancel_coupon")
public ResultVO<Boolean> cancelCoupon(@RequestBody CourseOrderVO orderVO, @RequestParam Integer couponId){
return orderService.cancelCoupon(orderVO, couponId);
}
@PostMapping("/pay/{orderId}")
public ResultVO<Boolean> payOrder(@PathVariable Integer orderId){
return orderService.payOrder(orderId);
}
/**
* 创建课程租用订单
* @param orderRentDTO
* @return
*/
@PostMapping("/rent")
public ResultVO<CourseOrderVO> createCourseRentOrder(@RequestBody OrderRentDTO orderRentDTO){
return orderService.createCourseRentOrder(orderRentDTO);
}
}
@RestController