基于SSM的网络在线考试系统

news2024/10/6 12:26:48

末尾获取源码
开发语言:Java
Java开发工具:JDK1.8
后端框架:SSM
前端:Vue
数据库:MySQL5.7和Navicat管理工具结合
服务器:Tomcat8.5
开发软件:IDEA / Eclipse
是否Maven项目:是


前言

基于SSM的网络在线考试系统有两大用户:

学生:首页、在线考试、公告信息、个人中心、后台管理模块功能。

管理员:学生管理、在线考试管理、试题管理、系统管理、考试管理。

前台页面

 首先我们进入基于SSM的网络在线考试系统可以看到有首页、在线考试、公告信息、个人中心、后台管理模块功能。

在首页我们可以看到有轮播图,轮播图是可以在管理员后台进行更换的,公告信息也是如此。 

 

在在线考试中,用户可以在这里查看管理员发布的在线考试内容,点击考试可以直接进入考试内容操作。 

在公告信息这里,用户可以查看管理员发布的公告信息情况。

如果没有账号的学生,可以在登录页面申请注册一个账号并且登录。

 

 登录后的学生可以在个人中心查看自己的信息并且可以修改。

后台模块

 管理员和学生后台登录页面。

管理员进入后台可以看到有学生管理、在线考试管理、试题管理、系统管理、考试管理。

在学生管理中,管理员可以管理学生信息。

在在线考试管理中,管理员可以管理考试,是否启用试卷或者禁用又或者可以添加新的试卷。

在试题管理中,管理员可以对题目进行添加。

在系统管理中的轮播图管理可以更换前台的图片播放。


登录模块核心代码


package com.controller;


import java.util.Arrays;
import java.util.Calendar;
import java.util.Date;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import com.annotation.IgnoreAuth;
import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.entity.TokenEntity;
import com.entity.UserEntity;
import com.service.TokenService;
import com.service.UserService;
import com.utils.CommonUtil;
import com.utils.MD5Util;
import com.utils.MPUtil;
import com.utils.PageUtils;
import com.utils.R;
import com.utils.ValidatorUtils;

/**
 * 登录相关
 */
@RequestMapping("users")
@RestController
public class UserController{
	
	@Autowired
	private UserService userService;
	
	@Autowired
	private TokenService tokenService;

	/**
	 * 登录
	 */
	@IgnoreAuth
	@PostMapping(value = "/login")
	public R login(String username, String password, String captcha, HttpServletRequest request) {
		UserEntity user = userService.selectOne(new EntityWrapper<UserEntity>().eq("username", username));
		if(user==null || !user.getPassword().equals(password)) {
			return R.error("账号或密码不正确");
		}
		String token = tokenService.generateToken(user.getId(),username, "users", user.getRole());
		return R.ok().put("token", token);
	}
	
	/**
	 * 注册
	 */
	@IgnoreAuth
	@PostMapping(value = "/register")
	public R register(@RequestBody UserEntity user){
//    	ValidatorUtils.validateEntity(user);
    	if(userService.selectOne(new EntityWrapper<UserEntity>().eq("username", user.getUsername())) !=null) {
    		return R.error("用户已存在");
    	}
        userService.insert(user);
        return R.ok();
    }

	/**
	 * 退出
	 */
	@GetMapping(value = "logout")
	public R logout(HttpServletRequest request) {
		request.getSession().invalidate();
		return R.ok("退出成功");
	}
	
	/**
     * 密码重置
     */
    @IgnoreAuth
	@RequestMapping(value = "/resetPass")
    public R resetPass(String username, HttpServletRequest request){
    	UserEntity user = userService.selectOne(new EntityWrapper<UserEntity>().eq("username", username));
    	if(user==null) {
    		return R.error("账号不存在");
    	}
    	user.setPassword("123456");
        userService.update(user,null);
        return R.ok("密码已重置为:123456");
    }
	
	/**
     * 列表
     */
    @RequestMapping("/page")
    public R page(@RequestParam Map<String, Object> params,UserEntity user){
        EntityWrapper<UserEntity> ew = new EntityWrapper<UserEntity>();
    	PageUtils page = userService.queryPage(params, MPUtil.sort(MPUtil.between(MPUtil.allLike(ew, user), params), params));
        return R.ok().put("data", page);
    }

	/**
     * 列表
     */
    @RequestMapping("/list")
    public R list( UserEntity user){
       	EntityWrapper<UserEntity> ew = new EntityWrapper<UserEntity>();
      	ew.allEq(MPUtil.allEQMapPre( user, "user")); 
        return R.ok().put("data", userService.selectListView(ew));
    }

    /**
     * 信息
     */
    @RequestMapping("/info/{id}")
    public R info(@PathVariable("id") String id){
        UserEntity user = userService.selectById(id);
        return R.ok().put("data", user);
    }
    
    /**
     * 获取用户的session用户信息
     */
    @RequestMapping("/session")
    public R getCurrUser(HttpServletRequest request){
    	Long id = (Long)request.getSession().getAttribute("userId");
        UserEntity user = userService.selectById(id);
        return R.ok().put("data", user);
    }

    /**
     * 保存
     */
    @PostMapping("/save")
    public R save(@RequestBody UserEntity user){
//    	ValidatorUtils.validateEntity(user);
    	if(userService.selectOne(new EntityWrapper<UserEntity>().eq("username", user.getUsername())) !=null) {
    		return R.error("用户已存在");
    	}
        userService.insert(user);
        return R.ok();
    }

    /**
     * 修改
     */
    @RequestMapping("/update")
    public R update(@RequestBody UserEntity user){
//        ValidatorUtils.validateEntity(user);
        userService.updateById(user);//全部更新
        return R.ok();
    }

    /**
     * 删除
     */
    @RequestMapping("/delete")
    public R delete(@RequestBody Long[] ids){
        userService.deleteBatchIds(Arrays.asList(ids));
        return R.ok();
    }
}

文件上传核心代码

package com.controller;

import java.io.File;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.util.Arrays;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Random;
import java.util.UUID;

import org.apache.commons.io.FileUtils;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpHeaders;
import org.springframework.http.HttpStatus;
import org.springframework.http.MediaType;
import org.springframework.http.ResponseEntity;
import org.springframework.util.ResourceUtils;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

import com.annotation.IgnoreAuth;
import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.entity.ConfigEntity;
import com.entity.EIException;
import com.service.ConfigService;
import com.utils.R;

/**
 * 上传文件映射表
 */
@RestController
@RequestMapping("file")
@SuppressWarnings({"unchecked","rawtypes"})
public class FileController{
	@Autowired
    private ConfigService configService;
	/**
	 * 上传文件
	 */
	@RequestMapping("/upload")
	public R upload(@RequestParam("file") MultipartFile file,String type) throws Exception {
		if (file.isEmpty()) {
			throw new EIException("上传文件不能为空");
		}
		String fileExt = file.getOriginalFilename().substring(file.getOriginalFilename().lastIndexOf(".")+1);
		File path = new File(ResourceUtils.getURL("classpath:static").getPath());
		if(!path.exists()) {
		    path = new File("");
		}
		File upload = new File(path.getAbsolutePath(),"/upload/");
		if(!upload.exists()) {
		    upload.mkdirs();
		}
		String fileName = new Date().getTime()+"."+fileExt;
		File dest = new File(upload.getAbsolutePath()+"/"+fileName);
		file.transferTo(dest);
		FileUtils.copyFile(dest, new File("C:\\Users\\Desktop\\jiadian\\springbootl7own\\src\\main\\resources\\static\\upload"+"/"+fileName));
		if(StringUtils.isNotBlank(type) && type.equals("1")) {
			ConfigEntity configEntity = configService.selectOne(new EntityWrapper<ConfigEntity>().eq("name", "faceFile"));
			if(configEntity==null) {
				configEntity = new ConfigEntity();
				configEntity.setName("faceFile");
				configEntity.setValue(fileName);
			} else {
				configEntity.setValue(fileName);
			}
			configService.insertOrUpdate(configEntity);
		}
		return R.ok().put("file", fileName);
	}
	
	/**
	 * 下载文件
	 */
	@IgnoreAuth
	@RequestMapping("/download")
	public ResponseEntity<byte[]> download(@RequestParam String fileName) {
		try {
			File path = new File(ResourceUtils.getURL("classpath:static").getPath());
			if(!path.exists()) {
			    path = new File("");
			}
			File upload = new File(path.getAbsolutePath(),"/upload/");
			if(!upload.exists()) {
			    upload.mkdirs();
			}
			File file = new File(upload.getAbsolutePath()+"/"+fileName);
			if(file.exists()){
				/*if(!fileService.canRead(file, SessionManager.getSessionUser())){
					getResponse().sendError(403);
				}*/
				HttpHeaders headers = new HttpHeaders();
			    headers.setContentType(MediaType.APPLICATION_OCTET_STREAM);    
			    headers.setContentDispositionFormData("attachment", fileName);    
			    return new ResponseEntity<byte[]>(FileUtils.readFileToByteArray(file),headers, HttpStatus.CREATED);
			}
		} catch (IOException e) {
			e.printStackTrace();
		}
		return new ResponseEntity<byte[]>(HttpStatus.INTERNAL_SERVER_ERROR);
	}
	
}

 封装代码

package com.utils;

import java.util.HashMap;
import java.util.Map;

/**
 * 返回数据
 */
public class R extends HashMap<String, Object> {
	private static final long serialVersionUID = 1L;
	
	public R() {
		put("code", 0);
	}
	
	public static R error() {
		return error(500, "未知异常,请联系管理员");
	}
	
	public static R error(String msg) {
		return error(500, msg);
	}
	
	public static R error(int code, String msg) {
		R r = new R();
		r.put("code", code);
		r.put("msg", msg);
		return r;
	}

	public static R ok(String msg) {
		R r = new R();
		r.put("msg", msg);
		return r;
	}
	
	public static R ok(Map<String, Object> map) {
		R r = new R();
		r.putAll(map);
		return r;
	}
	
	public static R ok() {
		return new R();
	}

	public R put(String key, Object value) {
		super.put(key, value);
		return this;
	}
}

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.coloradmin.cn/o/570071.html

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈,一经查实,立即删除!

相关文章

《Java并发编程实战》课程笔记(二)

可见性、原子性和有序性问题&#xff1a;并发编程 Bug 的源头 源头之一&#xff1a;缓存导致的可见性问题 在单核时代&#xff0c;所有的线程都是在一颗 CPU 上执行&#xff0c;CPU 缓存与内存的数据一致性容易解决。 因为所有线程都是操作同一个 CPU 的缓存&#xff0c;一个…

《面试1v1》ThreadLocal

我是 javapub&#xff0c;一名 Markdown 程序员从&#x1f468;‍&#x1f4bb;&#xff0c;八股文种子选手。 面试官&#xff1a; 你好&#xff0c;请问你对 ThreadLocal 有了解吗&#xff1f; 候选人&#xff1a; 您好&#xff0c;我知道 ThreadLocal 是一个 Java 中的类&a…

【坐标变换】坐标系坐标变换简单推导--未完待续

如图所示&#xff0c;假设已知坐标系 ( X , Y ) (X,Y) (X,Y)&#xff0c;旋转后的坐标系为 ( X ′ , Y ′ ) (X,Y) (X′,Y′)&#xff0c;旋转角度为 θ \theta θ&#xff0c;假设点p在 ( X , Y ) (X,Y) (X,Y)坐标系下为 ( x , y ) (x,y) (x,y)&#xff0c;坐标在旋转后的坐标…

速来!谷歌师兄的LeetCode刷题笔记开源了!

有小伙伴私聊我说刚开始刷LeetCode的时候&#xff0c;感到很吃力&#xff0c;刷题效率很低。我以前刷题的时候也遇到这个问题&#xff0c;直到后来看到这个谷歌师兄总结的刷题笔记&#xff0c;发现LeetCode刷题都是套路呀&#xff0c;掌握这些套路之后&#xff0c;就变得非常简…

kubernetes高可用+harbor高可用

kubernetes高可用harbor高可用 基于kubeadm安装kubernetes高可用集群全部主机环境初始化双主节点部署keepalive双主节点初始化kubeadm在k8smaster1节点上初始化k8s在k8smaster2节点上做扩容操作 harbor高可用集群初始化harbor1节点安装环境在另一台节点上配置使用私有harbor仓库…

初学QT:使用QtDesigner绘制一个简单的界面(Day01)

关于Qt 打算在这里记录我学习qt过程中遇见的问题的收获 今天是学习qt的第一天&#xff0c;首先找了一个界面打算照着这个界面写一个一样的 因为是第一天&#xff0c;所以我用的是qt designer写的 其中遇到的问题&#xff1a; 设置背景图片 首先不能直接添加图片到背景图片中…

如何在华为OD机试中获得满分?Java实现【分界线】一文详解!

✅创作者&#xff1a;陈书予 &#x1f389;个人主页&#xff1a;陈书予的个人主页 &#x1f341;陈书予的个人社区&#xff0c;欢迎你的加入: 陈书予的社区 &#x1f31f;专栏地址: Java华为OD机试真题&#xff08;2022&2023) 文章目录 1. 题目描述2. 输入描述3. 输出描述…

在 Alma Linux 9 上安装 Node.js 的 3 种不同方法

Node.js 是一个基于 Chrome V8 引擎的 JavaScript 运行时&#xff0c;用于构建快速、可扩展的网络应用程序。在 Alma Linux 9 上安装 Node.js 可以为开发者提供强大的工具和库来开发服务器端应用程序。 本文将介绍三种不同的方法来安装 Node.js 在 Alma Linux 9 上。 1. 方法一…

LLMs的自动化工具系统(HuggingGPT、AutoGPT、WebGPT、WebCPM)

在前面两篇博文中已经粗略介绍了增强语言模型和Tool Learning&#xff0c;本篇文章看四篇代表性的自动化框架&#xff0c;HuggingGPT、AutoGPT、WebGPT、WebCPM。 Augmented Language Models&#xff08;增强语言模型&#xff09;Toolformer and Tool Learning&#xff08;LLM…

chatgpt赋能python:了解PythonSpace:Python编程中的重要概念

了解Python Space&#xff1a;Python编程中的重要概念 Python Space是Python编程的一个关键概念&#xff0c;可以帮助你更好地理解Python中的命名空间和作用域。在这篇文章中&#xff0c;我们将深入探讨Python Space&#xff0c;介绍命名空间的概念&#xff0c;讨论命名空间和…

支付系统设计四:支付核心设计03-快捷发送短信(失败转代扣)

文章目录 前言一、背景1. 应用架构2. 分层支撑机制 二、银行卡快捷支付1. 用户操作流程2. 系统执行流程--正常2.1 发送短信2.2 短信确认 3. 系统执行流程--异常3.1 异常环节3.1.1 路由失败3.1.2 调用支付渠道失败 3.2 异常处理3.2.1 路由失败3.2.2 调用支付渠道失败 4. 流程解析…

指导实验心得5篇实用技巧

指导实验心得1 我觉得化工原理实验是一门验证性课程&#xff0c;它把我们在化工原理学到的各种单元操作化为实实在在的东西&#xff0c;而让我们把学到的知识认识到它的实在性。流体输送——离心泵、过滤——板框压滤机、对流传热——套管式换热器、吸收蒸馏——填料塔板式塔、…

AF594 NHS,Alexa Fluor594 NHS Ester,AF 594 NHS 活化酯,用于成像和流式细胞术中的稳定信号生成

【产品描述】 陕西新研博美生物科技有限公司供应的​Alexa Fluor594是一种鲜红色染料。Alexa Fluor用于成像和流式细胞术中的稳定信号生成 594染料是水溶性的&#xff0c;并且从pH 4到pH 10对pH不敏感。Alexa Fluor 594染料与多种抗体、肽、蛋白质、示踪剂和扩增底物偶联&#…

java内存问题

各种OOM的情况 1. 堆溢出-java.lang.OutOfMemoryError: Java heap space。 2. 栈溢出-java.lang.OutOfMemorryError。 3. 栈溢出-java.lang.StackOverFlowError。 4. 元信息溢出-java.lang.OutOfMemoryError: Metaspace。 5. 直接内存溢出-java.lang.OutOfMemoryError: Direct …

软件开发工程师个人简历模板3篇

软件开发工程师个人简历模板篇1 姓 名&#xff1a; 张先生 性 别&#xff1a; 男 婚姻状况&#xff1a; 未婚 民 族&#xff1a; 汉族 户 籍&#xff1a; 广东-珠海 年 龄&#xff1a; 28 现所在地&#xff1a; 广东-珠海 身 高&#xff1a; 168cm 希望地区&#xff1a; …

Toolformer and Tool Learning(LLMs如何使用工具)

大模型的能力让学术和工业界都对通用人工智能的未来充满幻想&#xff0c;在前一篇博文中已经粗略介绍&#xff0c; Augmented Language Models&#xff08;增强语言模型&#xff09; ALM的两大思路是推理和工具&#xff0c;本篇博文整理两篇关于Toolformer或Tool Learning的论…

web实现日历、阳历农历之间相互转换、npm、push、unshift、includes、innerHTML

文章目录 1、原生web实现效果图htmlJavaScriptstyle vue2实现htmlJavaScript 1、原生web实现 效果图 html <div class"box"><div class"week"><div>星期日</div><div>星期一</div><div>星期二</div><…

Three.js--》建模软件如何加载外部3D模型?

目录 三维建模软件的介绍 Blender官方文档介绍 Blender软件安装 GLTF格式简介 gltf不同文件形式 看过我之前讲解的three文章的人都知道&#xff0c;我在创建模型的时候都没有使用three.js自带的一些简单模型&#xff0c;而是引入外部的模型并加载到页面上&#xff0c;简言…

数据库基础——1.数据库概述

从这篇文章我们开始学习数据库的相关知识 目录 1.为什么要使用数据库 2.数据库与数据库管理系统 2.1相关概念 2.2数据库与数据库管理系统的关系 ​编辑2.3常见的数据库管理系统 2.4常见的数据库介绍 3.MySQL介绍 3.1概述 3.2关于MySQL8.0 3.3 Oracle vs MySQL 4.RD…

Java 反序列化漏洞

反序列化漏洞是指程序在反序列化期间&#xff0c;通过特殊的调用链引发的一系列安全问题。编程语言中只要存在序列化&#xff0c;反序列化功能就可能存在反序列化的安全问题。这里只针对Java和PHP进行讨论。 序列化漏洞概述 序列化的存在主要是为了存储和传输&#xff0c;将这…