作者主页:夜未央5788
简介:Java领域优质创作者、Java项目、学习资料、技术互助
文末获取源码
项目介绍
管理员:
登录,修改个人资料,用户管理,公告管理,教室管理,科目管理,听课记录管理等功能。
用户角色包含以下功能:
用户登录,修改个人资料,查看公告,查看听课记录等功能。
环境需要
1.运行环境:最好是java jdk 1.8,我们在这个平台上运行的。其他版本理论上也可以。
2.IDE环境:IDEA,Eclipse,Myeclipse都可以。推荐IDEA;
3.tomcat环境:Tomcat 7.x,8.x,9.x版本均可
4.硬件环境:windows 7/8/10 1G内存以上;或者 Mac OS;
5.数据库:MySql 5.7版本;
技术栈
1. 后端:Spring+SpringMVC+Mybatis
2. 前端:HTML+CSS+JavaScript+jsp
使用说明
1. 使用Navicat或者其它工具,在mysql中创建对应名称的数据库,并导入项目的sql文件;
2. 使用IDEA/Eclipse/MyEclipse导入项目,Eclipse/MyEclipse导入时,若为maven项目请选择maven;若为maven项目,导入成功后请执行maven clean;maven install命令,然后运行;
3. 将项目中application.yml配置文件中的数据库配置改为自己的配置;
4. 运行项目,http://localhost:8080/shop/index
运行截图
相关代码
学生信息
package com.taohan.online.exam.charts;
import java.util.Map;
import java.util.Set;
import org.springframework.stereotype.Repository;
import com.github.abel533.echarts.axis.CategoryAxis;
import com.github.abel533.echarts.axis.ValueAxis;
import com.github.abel533.echarts.code.Magic;
import com.github.abel533.echarts.code.Tool;
import com.github.abel533.echarts.code.Trigger;
import com.github.abel533.echarts.code.X;
import com.github.abel533.echarts.code.Y;
import com.github.abel533.echarts.feature.MagicType;
import com.github.abel533.echarts.json.GsonOption;
import com.github.abel533.echarts.series.Line;
import com.taohan.online.exam.po.ClassInfo;
/**
*
* <p>Title: StudentCount</p>
* <p>Description: (年级下/所有)班级的学生总量 相关图表Json数据生成</p>
* @author: taohan
* @date: 2018-9-17
* @time: 下午7:03:13
* @version: 1.0
*/
@Repository
public class StudentCount {
/**
* 班级对应学生人数折线图
* @param data
* @return
*/
public static String createBarJson(Map<String, Object> data) {
Set<String> set = data.keySet();
GsonOption option = new GsonOption();
option.title().text("班级学生数量统计").x(X.center).y(Y.top).borderWidth(1).textStyle().color("#438EB9");
option.toolbox().show(true).feature(Tool.mark, Tool.restore, new MagicType(Magic.bar, Magic.line), Tool.saveAsImage).x(X.right).y(Y.top);
//数据默认触发, 鼠标移入显示竖线 trigger(Trigger.axis)
option.tooltip().formatter("{b} {c}人").trigger(Trigger.axis);
option.legend().data("班级总人数").x(X.center).y(Y.bottom).borderWidth(1);
Line line = new Line("班级总人数");
//值轴
ValueAxis valueAxis = new ValueAxis();
valueAxis.axisLabel().formatter("{value}人").textStyle().color("#438EB9");
//valueAxis.min(0);
option.yAxis(valueAxis);
//类目轴
CategoryAxis categoryAxis = new CategoryAxis();
//interval(0):设置横轴信息全部显示
//rotate(-30):设置 -30 度角倾斜显示
categoryAxis.axisLabel().interval(0).rotate(-30).textStyle().color("#438EB9");
for (String className : set) {
categoryAxis.data(className);
ClassInfo classInfo = (ClassInfo)data.get(className);
line.data(classInfo.getClassId());
}
option.xAxis(categoryAxis);
line.smooth(true);
option.series(line);
option.grid().x(100);
System.out.println(option.toString());
return option.toString();
}
}
学生成绩
package com.taohan.online.exam.charts;
import java.util.List;
import com.github.abel533.echarts.axis.CategoryAxis;
import com.github.abel533.echarts.axis.ValueAxis;
import com.github.abel533.echarts.code.Magic;
import com.github.abel533.echarts.code.PointerType;
import com.github.abel533.echarts.code.Tool;
import com.github.abel533.echarts.code.Trigger;
import com.github.abel533.echarts.code.X;
import com.github.abel533.echarts.code.Y;
import com.github.abel533.echarts.feature.MagicType;
import com.github.abel533.echarts.json.GsonOption;
import com.github.abel533.echarts.series.Bar;
import com.github.abel533.echarts.series.Line;
import com.taohan.online.exam.po.StudentExamInfo;
/**
*
* <p>Title: StudentExamInfoCharts</p>
* <p>Description: 学生考试信息 图表 Json 数据 生成</p>
* @author: taohan
* @date: 2018-9-19
* @time: 上午10:26:55
* @version: 1.0
*/
public class StudentExamInfoCharts {
public static String createExamCountBarJson(List<StudentExamInfo> examInfos) {
GsonOption option = new GsonOption();
option.title().text("学生考试次数统计").x(X.center).y(Y.top).borderWidth(1).textStyle().color("#438EB9");
option.toolbox().show(true).feature(Tool.mark, Tool.restore, new MagicType(Magic.bar, Magic.line), Tool.saveAsImage).x(X.right).y(Y.top);
option.tooltip().show(true).formatter("{b} {c}次");
option.legend().data("学生考试次数统计").x(X.center).y(Y.bottom);
Bar bar = new Bar();
//值轴
ValueAxis valueAxis = new ValueAxis();
//设置y轴不出现小数值
valueAxis.interval(1);
valueAxis.axisLabel().formatter("{value} 次");
option.yAxis(valueAxis);
//类目轴
CategoryAxis categoryAxis = new CategoryAxis();
categoryAxis.axisLabel().interval(0);
for (StudentExamInfo studentExamInfo : examInfos) {
bar.data(studentExamInfo.getExamSum());
categoryAxis.data(studentExamInfo.getStudentName());
}
bar.barCategoryGap("20");
option.xAxis(categoryAxis);
option.series(bar);
return option.toString();
}
public static String createAvgCountLineJson(List<StudentExamInfo> examInfos) {
GsonOption option = new GsonOption();
option.title().text("学生考试平均成绩统计").x(X.center).y(Y.top).borderWidth(1).textStyle().color("#438EB9");
option.toolbox().show(true).feature(Tool.mark, Tool.restore, new MagicType(Magic.bar, Magic.line), Tool.saveAsImage).x(X.right).y(Y.top);
option.tooltip().show(true).trigger(Trigger.axis).axisPointer().type(PointerType.cross).crossStyle().color("#999");
option.legend().data("考试次数", "平均分").x(X.center).y(Y.bottom);
Line line = new Line("考试次数").smooth(true);
Bar bar = new Bar("平均分");
//值轴
ValueAxis valueAxis = new ValueAxis();
//设置y轴不出现小数值
valueAxis.interval(1);
valueAxis.axisLabel().formatter("{value} 次");
//option.yAxis(valueAxis);
ValueAxis valueAxis1 = new ValueAxis();
valueAxis1.interval(1);
valueAxis1.axisLabel().formatter("{value} 分");
option.yAxis(valueAxis, valueAxis1);
//类目轴
CategoryAxis categoryAxis = new CategoryAxis();
categoryAxis.axisLabel().interval(0);
for (StudentExamInfo studentExamInfo : examInfos) {
if (studentExamInfo.getAvgScore() != null || studentExamInfo.getExamSum() != 0) {
bar.data(studentExamInfo.getAvgScore()/studentExamInfo.getExamSum());
} else {
bar.data("暂无记录");
}
line.data(studentExamInfo.getExamSum());
categoryAxis.data(studentExamInfo.getStudentName());
}
//实现双 y 轴,使用 yAxisIndex() 指定应用到哪个 y 轴
bar.barCategoryGap("20").yAxisIndex(1);
option.xAxis(categoryAxis);
option.series(bar, line);
return option.toString();
}
public static String createStudentExamLineJson(List<StudentExamInfo> examInfos) {
GsonOption option = new GsonOption();
option.title().text("学生考试试卷得分统计").x(X.center).y(Y.top).borderWidth(1).textStyle().color("#438EB9");
option.toolbox().show(true).feature(Tool.mark, Tool.restore, new MagicType(Magic.bar, Magic.line), Tool.saveAsImage).x(X.right).y(Y.top);
option.tooltip().show(true).formatter("{b} {c}分").trigger(Trigger.axis);
option.legend().data("得分").x(X.center).y(Y.bottom);
Line line = new Line("试卷得分");
//值轴
ValueAxis valueAxis = new ValueAxis();
//设置y轴不出现小数值
valueAxis.interval(1);
valueAxis.axisLabel().formatter("{value} 分");
option.yAxis(valueAxis);
//类目轴
CategoryAxis categoryAxis = new CategoryAxis();
categoryAxis.axisLabel().interval(0).rotate(-30);
for (StudentExamInfo studentExamInfo : examInfos) {
line.data(studentExamInfo.getExamScore());
categoryAxis.data(studentExamInfo.getExamPaperName());
}
option.xAxis(categoryAxis);
option.series(line);
System.out.println(option.toString());
return option.toString();
}
}
试卷试题
package com.taohan.online.exam.handler;
import java.io.IOException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Random;
import javax.security.auth.Subject;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.servlet.ModelAndView;
import com.google.gson.Gson;
import com.taohan.online.exam.po.CourseInfo;
import com.taohan.online.exam.po.ExamPaperInfo;
import com.taohan.online.exam.po.ExamSubjectMiddleInfo;
import com.taohan.online.exam.po.GradeInfo;
import com.taohan.online.exam.po.SubjectInfo;
import com.taohan.online.exam.service.ExamPaperInfoService;
import com.taohan.online.exam.service.ExamSubjectMiddleInfoService;
import com.taohan.online.exam.service.SubjectInfoService;
/**
*
* <p>Title: ExamSubjectMiddleInfoHandler</p>
* <p>Description: 试卷试题--关联</p>
* @author: taohan
* @date: 2018-8-20
* @time: 下午4:21:05
* @version: 1.0
*/
@Controller
@Scope("prototype")
@SuppressWarnings("all")
public class ExamSubjectMiddleInfoHandler {
@Autowired
private ExamSubjectMiddleInfoService esmService;
@Autowired
private ExamPaperInfoService examPaperInfoService;
@Autowired
private SubjectInfoService subjectInfoService;
@Autowired
private ExamSubjectMiddleInfo esm;
@Autowired
private ExamPaperInfo examPaper;
@Autowired
private SubjectInfo subject;
@Autowired
private CourseInfo course;
@Autowired
private GradeInfo grade;
@Autowired
private Gson gson;
private Logger logger = Logger.getLogger(ExamSubjectMiddleInfoHandler.class);
/**
* 查询试卷-试题信息
* 根据多条件查询
* @param examPaperId 试卷编号
* @param courseName 科目名称
* @param courseId 科目百年好
* @param gradeId 年级编号
* @param response
* @throws IOException
*/
@RequestMapping(value="/getESM", method={RequestMethod.GET, RequestMethod.POST})
public void getExamPaperWithSubject(
@RequestParam(value="examPaperId", required=false) Integer examPaperId,
@RequestParam(value="courseName", required=false) String courseName,
@RequestParam(value="courseId", required=false) Integer courseId,
@RequestParam(value="gradeId", required=false) Integer gradeId,
HttpServletResponse response) throws IOException {
ModelAndView model = new ModelAndView();
/*条件处理*/
if (examPaperId != null) examPaper.setExamPaperId(examPaperId);
if (courseName != null) course.setCourseName(courseName);
if (courseId != null) course.setCourseId(courseId);
if (gradeId != null) grade.setGradeId(gradeId);
subject.setCourse(course);
subject.setGrade(grade);
esm.setExamPaper(examPaper);
esm.setSubject(subject);
logger.info("查询试卷试题信息 With "+esm);
List<ExamSubjectMiddleInfo> esms = esmService.getExamPaperWithSubject(esm);
response.getWriter().print(gson.toJson(esms));
}
/**
* 手动添加试题
* 手动将选择的试题添加到指定试卷中 -- 正式添加处理
* @param examPaperId 试卷编号
* @param session
* @param response
* @throws Exception
*/
@RequestMapping(value="/handAdd", method={RequestMethod.GET, RequestMethod.POST})
public void isHandAddSubjectToExamPaper(
@RequestParam(value="examPaperId") Integer examPaperId,
HttpSession session,
HttpServletResponse response) throws Exception {
//添加试题总分统计
int scoreSum = 0;
//添加试题总量统计
int subjectSum = 0;
Map<String, Object> map = new HashMap<String, Object>();
map.put("examPaperId", examPaperId);
ArrayList<Integer> subjectIds = new ArrayList<Integer>();
//试题信息
List<String> ids = (List<String>) session.getAttribute("ids");
if (ids != null) {
for (String is : ids) {
//分割试题编号和分数
String[] idAndScore = is.split(",");
subjectIds.add(Integer.parseInt(idAndScore[0]));
//累加试题分数
scoreSum += Integer.parseInt(idAndScore[1]);
//累加试题数量
subjectSum += 1;
}
/** 需要添加试题集合 */
map.put("subjectIds", subjectIds);
} else {
logger.error("试题集合为空,不能进行添加试题操作!");
response.getWriter().print("需要添加的试题为空,操作失败!");
return;
}
logger.info("添加试题集合到试卷 "+examPaperId);
//总分和题目数量信息
Map<String, Object> scoreWithNum = new HashMap<String, Object>();
scoreWithNum.put("subjectNum", subjectSum);
scoreWithNum.put("score", scoreSum);
scoreWithNum.put("examPaperId", examPaperId);
/** 修改试卷总分 */
examPaperInfoService.isUpdateExamPaperScore(scoreWithNum);
/** 修改试卷试题总量 */
examPaperInfoService.isUpdateExamPaperSubjects(scoreWithNum);
/** 添加试题到试卷中 */
esmService.isAddESM(map);
response.getWriter().print("试题已成功添加到试卷中!");
}
/**
* 手动添加试题到试卷时 向 Session中存入试题信息
* @param subjectId 试题编号
* @param examPaperId 试卷编号
* @param score 试题分数
* @param handle 操作标识, 自动 OR 手动
* @param session
* @param response
* @throws IOException
*/
@RequestMapping("/getChooseSubId")
public void getChooseSubjectId(
@RequestParam("subjectId") Integer subjectId,
@RequestParam("examPaperId") Integer examPaperId,
@RequestParam("score") Integer score,
@RequestParam(value="handle", required=false) Integer handle,
HttpSession session, HttpServletResponse response) throws IOException {
List<String> ids = null;
/*
* 添加到 Session 中需先判断该试题是否已经存在该试卷中
* 如果存在,则不进行添加;反之添加
*/
examPaper.setExamPaperId(examPaperId);
subject.setSubjectId(subjectId);
esm.setExamPaper(examPaper);
esm.setSubject(subject);
/** 验证添加记录 是否已经存在 */
Integer esmId = esmService.getEsmByExamIdWithSubjectId(esm);
if (esmId == null) {
logger.error("需要添加的试题 "+subjectId+" 暂不存在试卷 "+examPaperId+" 中,可进行添加");
ids = (List<String>) session.getAttribute("ids");
/** Session 记录非空验证 */
if (subjectId != null && score != null) {
//第一次添加
if (ids == null) {
ids = new ArrayList<String>();
ids.add((subjectId+","+score));
logger.info("Session 添加试题:是否手动"+handle+", 试题编号:"+subjectId+", 试题分数"+score);
} else {
//存在就移除,反之添加
if (ids.contains((subjectId+","+score))) {
ids.remove((subjectId+","+score));
logger.info("Session 移除试题:是否手动"+handle+", 试题编号:"+subjectId+", 试题分数"+score);
} else {
ids.add((subjectId+","+score));
logger.info("Session 添加试题:是否手动"+handle+", 试题编号:"+subjectId+", 试题分数"+score);
}
}
} else {
logger.error("添加试题 "+subjectId+" 到 Session 失败");
response.getWriter().print("添加失败,试题编号或试题分数异常!");
return;
}
} else {
logger.error("需要添加的试题 "+subjectId+" 已经存在试卷 "+examPaperId+" 中了, 无法进行添加");
//同时返回添加失败的题号,用于前台方便移除选中
response.getWriter().print("f-exists-"+subjectId);
return;
}
session.setAttribute("ids", ids);
response.getWriter().print("编号为 "+subjectId+" 的试题添加成功");
}
/**
* 清空Session中保存的试题编号集合
* @param session
* @return
*/
@RequestMapping("/clearSubjectIdsWithSession")
public String isClearChooseSubjectIds(HttpSession session) {
logger.info("清空 Session 中需要添加的试题编号集合");
session.removeAttribute("ids");
return "redirect:examPapers";
}
/**
* 从试卷中移除试题
* @param subjectId 试题编号
* @param examPaperId 试卷百年好
* @param score 试题分数
* @param response
* @throws IOException
*/
@RequestMapping(value="/removeSubjectFromPaper", method={RequestMethod.GET, RequestMethod.POST})
public void removeSubjectWithExamPaper(
@RequestParam("subjectId") Integer subjectId,
@RequestParam("examPaperId") Integer examPaperId,
@RequestParam("score") Integer score,
HttpServletResponse response) throws IOException {
logger.info("从试卷 "+examPaperId+" 中移除试题 "+subjectId+",试题分值:"+score);
Map<String, Object> map = new HashMap<String, Object>();
map.put("subjectNum", (-1));
map.put("score", (-score));
map.put("examPaperId", examPaperId);
map.put("subjectId", subjectId);
//修改试卷总分
examPaperInfoService.isUpdateExamPaperScore(map);
//修改试卷题目数量
examPaperInfoService.isUpdateExamPaperSubjects(map);
//从试卷中移除试题
esmService.removeSubjectWithExamPaper(map);
response.getWriter().print("t");
}
/**
* 自动生成试题到试卷
* @param examPaperId 试卷编号
* @param subjectEasy 试题难易程度
* @param courseId 科目编号
* @param gradeId 年级编号
* @param subjectSum 生成试题数量
* @param response
* @throws IOException
*/
@RequestMapping("/autoAddSubject")
public void isAutoAddSubjectToExamPaper(
@RequestParam(value="examPaperId") Integer examPaperId,
@RequestParam(value="subjectEasy", required=false) Integer subjectEasy,
@RequestParam(value="courseId", required=false) Integer courseId,
@RequestParam(value="gradeId", required=false) Integer gradeId,
@RequestParam("subjectSum") Integer subjectSum,
HttpServletResponse response) throws IOException {
Random random = new Random();
/*生成条件处理*/
if (subjectEasy != null) {
subject.setSubjectEasy(subjectEasy);
}
if (courseId != null) {
course.setCourseId(courseId);
subject.setCourse(course);
}
if (gradeId != null) {
grade.setGradeId(gradeId);
subject.setGrade(grade);
}
Map<String, Object> map = new HashMap<String, Object>();
map.put("subject", subject);
map.put("startIndex", null);
map.put("pageShow", null);
List<SubjectInfo> subjects = subjectInfoService.getSubjects(map);
int subjectTotal = subjects.size()-1;
Map<String, Object> addMap = new HashMap<String, Object>();
ArrayList<Integer> indexs = new ArrayList<Integer>();
ArrayList<Integer> subjectIds = new ArrayList<Integer>();
//添加试题总分
int score = 0;
for (int i=0; i<subjectSum; i++) {
//产生随机索引
int index = random.nextInt(subjectTotal);
if (indexs.contains(index)) { //随机索引已经存在
i--;
continue;
} else {
indexs.add(index);
int subjectId = subjects.get(index).getSubjectId();
subjectIds.add(subjectId);
score += subjects.get(index).getSubjectScore();
logger.info("索引 "+index+" 试题编号 "+subjectId+" 成立");
}
}
//添加试题信息
addMap.put("examPaperId", examPaperId);
addMap.put("subjectIds", subjectIds);
//总分和题目数量信息
Map<String, Object> scoreWithNum = new HashMap<String, Object>();
scoreWithNum.put("subjectNum", subjectSum);
scoreWithNum.put("score", score);
scoreWithNum.put("examPaperId", examPaperId);
//修改试卷总分
examPaperInfoService.isUpdateExamPaperScore(scoreWithNum);
//修改试卷题目数量
examPaperInfoService.isUpdateExamPaperSubjects(scoreWithNum);
//添加
logger.info("添加试题到试卷 "+examPaperId);
esmService.isAddESM(addMap);
response.getWriter().print("t");
}
}
如果也想学习本系统,下面领取。回复:196ssm
本文含有隐藏内容,请 开通VIP 后查看