计算机毕业设计 SpringMVC计算机专业认证在线考试系统


0 项目说明

基于SpringMVC的计算机专业认证在线考试系统

提示:适合用于课程设计或毕业设计,工作量达标,源码开放

项目分享:

https://gitee.com/asoonis/feed-neo


1 功能模块图

在这里插入图片描述

2 技术选型

1、前端

  • Html/Css/JavaScript
  • Bootstrap
  • jQuery
  • UploadFive

2、后端

  • Spring/SpringMVC/Hibernate
  • Spring Security
  • slf4j/log4j
  • Gson
  • POI
  • Druid

3、数据库

  • MySQL

3 ER图

在这里插入图片描述

4 界面展示

在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述

5 项目包结构

在这里插入图片描述
在这里插入图片描述

6 项目源码

package pers.corvey.exam.controller;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpHeaders;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.multipart.MultipartFile;

import pers.corvey.exam.controller.common.BaseControllerImpl;
import pers.corvey.exam.entity.Resource;
import pers.corvey.exam.entity.ui.CallBackMessage;
import pers.corvey.exam.exception.FileNotPermitException;
import pers.corvey.exam.service.BuyLogService;
import pers.corvey.exam.service.ResourceService;
import pers.corvey.exam.util.CurrentUtils;
import pers.corvey.exam.util.MyFileUtils;

@Controller
@RequestMapping("/resource")
public class ResourceController extends BaseControllerImpl<Resource, Long> {
	
	private final ResourceService service;
	private final BuyLogService buyLogService;
	
	@Autowired
	public ResourceController(ResourceService service, BuyLogService buyLogService) {
		super(service, "resource-input.jsp", "resource-list.jsp");
		this.service = service;
		this.buyLogService = buyLogService;
		needEntityURLSuffix.add("/download");
	}
	
	@PostMapping("/upload")
	public String upload(Model model, @ModelAttribute("entity") Resource entity,
			@RequestParam("file") MultipartFile multipartFile) {
		save(model, entity, multipartFile);
		return redirect("/all");
	}
	
	@PostMapping(SAVE_PATH)
	public String save(Model model, @ModelAttribute("entity") Resource entity,
			@RequestParam("file") MultipartFile multipartFile) {
		CallBackMessage msg;
		if (multipartFile.getSize() <= 0) {
			msg = CallBackMessage.createDangerMsg("必须上传文件!");
		} else {
			try {
				File file = MyFileUtils.saveFile(multipartFile);
				entity.setFileName(multipartFile.getOriginalFilename());
				entity.setFileSize(multipartFile.getSize());
				entity.setFilePath(file.getPath());
				return baseSave(entity);
			} catch (IOException e) {
				e.printStackTrace();
				msg = CallBackMessage.createDangerMsg("上传文件失败,服务器发生未知异常!");
			} catch (FileNotPermitException e) {
				msg = CallBackMessage.createDangerMsg(e.getMessage());
			}
		}
		CurrentUtils.addAttributeToSession(CallBackMessage.MESSAGE_ATTRIBUTE_NAME, msg);
		return redirect(LIST_PATH);
	}

	@RequestMapping("/download")
	public ResponseEntity<byte[]> download(@ModelAttribute("entity") Resource entity) {
		if (entity == null || entity.getId() == null) {
			return null;
		}
		// 购买失败
		if (!buyLogService.buy(entity)) {
			return null;	// XXX 无法下载时返回的页面不够友好
		}
		try {
			File file = new File(entity.getFilePath());
			InputStream is = new FileInputStream(file);
			byte[] body = new byte[is.available()];
			is.read(body);
			HttpHeaders headers = new HttpHeaders();
			headers.add("Content-Disposition", "attchement;filename=" + file.getName());
			HttpStatus statusCode = HttpStatus.OK;
			ResponseEntity<byte[]> ret = new ResponseEntity<byte[]>(body, headers, statusCode);
			is.close();
			return ret;
		} catch (FileNotFoundException e) {
			CallBackMessage msg = CallBackMessage.createDangerMsg("服务器发生异常,请重试!");
			msg.addToCurrentSession();
			e.printStackTrace();
		} catch (IOException e) {
			CallBackMessage msg = CallBackMessage.createDangerMsg("服务器发生异常,请重试!");
			msg.addToCurrentSession();
			e.printStackTrace();
		}
		return null;	// XXX 无法下载时返回的页面不够友好
	}
	
	@RequestMapping("/all")
	public String all(Model model) {
		List<Resource> resources = service.findAll();
		model.addAttribute("entities", resources);
		return "resource-all";
	}
	
	@RequestMapping("/adminSearch")
	public String adminSearch(Model model, @RequestParam("keyword") String keyword) {
		return baseShowListView(model, service.search(keyword));
	}
	
	@RequestMapping("/search")
	public String search(Model model, @RequestParam("keyword") String keyword) {
		Iterable<Resource> resources = service.search(keyword);
		model.addAttribute("entities", resources);
		return "resource-all";
	}
	
	@RequestMapping("/{resourceId}")
	public String show(Model model, @PathVariable Long resourceId) {
		Resource resource = service.findByID(resourceId);
		model.addAttribute("resource", resource);
		
		boolean hadBought = buyLogService.hadBought(resource);
		model.addAttribute("hadBought", hadBought);
		System.out.println(hadBought);
		return "resource-show";
	}
}

项目分享:

https://gitee.com/asoonis/feed-neo

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值