基于javaweb+mysql的在线教学考试作业系统(后台、前台)
运行环境
Java≥8、MySQL≥5.7
开发工具
eclipse/idea/myeclipse/sts等均可配置运行
适用
课程设计,大作业,毕业设计,项目练习,学习演示等
功能说明
管理员:用户管理、班级、题库、考试、作业等模块管理
学生:考试、写作业
前台
后台
技术框架
JSP JavaScript layui SpringBoot SpringMVC MyBatis
* </p>
*
* @author Janus
*/
@Controller
@RequestMapping({"/userPaper","/home/userPaper"})
public class UserPaperController {
private static final Logger logger= LoggerFactory.getLogger(UserPaperController.class);
@Autowired
SysClassService classService;
@Autowired
SysUserService userService;
public ResponseEntity<byte[]> fileExport(String fileName, HttpServletRequest request){
byte [] body = null;
InputStream in=null;
try {
//获取到文件流
in = FileController.class.getClassLoader().getResourceAsStream(fileName);
if(in.available()<1){
logger.info("没有从classpath下获取到导出的模板文件,将从configJsonPath下重试:{}",configJsonPath);
in=new FileInputStream(new File(configJsonPath+File.separator+fileName));
}
logger.debug("需要导出的模板:{},获取的流为:{}",fileName,in);
body = new byte[in.available()];
logger.debug("导出模板大小:{},读入body大小:{}",in.available(),body.length);
in.read(body);
//添加响应头
HttpHeaders headers = new HttpHeaders();
headers.add("Content-Disposition", "attachment;filename="+FileUtils.setFileDownloadHeader(request, fileName));
headers.setContentType(MediaType.APPLICATION_OCTET_STREAM);
HttpStatus statusCode = HttpStatus.OK;
background-color:#222222;
}
#socket, #socket a{
color:#aaaaaa;
}
#top .portfolio-title, .portfolio-sort-container .inner-entry, .ajax_loading, .ajax-control a, .inner_column, .ajax_slide .inner_slide, #top .ajax_slide .slideshow, #top .inner-entry .slideshow, .ajax_slide .entry-content{
background-color:#ffffff;
}
#top .portfolio-title, #top .portfolio-title a, #top .portfolio-title a:hover, .ajax-control a, .ajax_slide h1, .ajax_slide h2, .ajax_slide h3, .ajax_slide h4, .ajax_slide h5, .ajax_slide h6, .ajax_slide strong, .ajax_slide a{
color:#222222;
}
try {
//获取到文件流
InputStream in = new FileSystemResource(fileUrl).getInputStream();
body = new byte[in.available()];
in.read(body);
} catch (IOException e1) {
logger.debug("文件读入出错,文件路径为:"+fileUrl);
e1.printStackTrace();
}
//添加响应头
HttpHeaders headers = new HttpHeaders();
headers.add("Content-Disposition", "attachment;filename="+ FileUtils.setFileDownloadHeader(request, fileName));
headers.setContentType(MediaType.APPLICATION_OCTET_STREAM);
HttpStatus statusCode = HttpStatus.OK;
int strWidth1 = outg.getFontMetrics().stringWidth(productName1);
int strWidth2 = outg.getFontMetrics().stringWidth(productName2);
outg.drawString(productName1, 200 - strWidth1/2, source.getHeight() + (outImage.getHeight() - source.getHeight())/2 + 12 );
BufferedImage outImage2 = new BufferedImage(400, 485, BufferedImage.TYPE_4BYTE_ABGR);
Graphics2D outg2 = outImage2.createGraphics();
outg2.drawImage(outImage, 0, 0, outImage.getWidth(), outImage.getHeight(), null);
outg2.setColor(Color.BLACK);
outg2.setFont(new Font("宋体",Font.BOLD,30)); //字体、字型、字号
outg2.drawString(productName2, 200 - strWidth2/2, outImage.getHeight() + (outImage2.getHeight() - outImage.getHeight())/2 + 5 );
outg2.dispose();
outImage2.flush();
outImage = outImage2;
}else {
outg.drawString(productName, 200 - strWidth/2 , source.getHeight() + (outImage.getHeight() - source.getHeight())/2 + 12 ); //画文字
}
outg.dispose();
outImage.flush();
source=outImage;
source.flush();
public static String getPreviousMonthFirstDay() {
String str = "";
Calendar lastDate = Calendar.getInstance();
lastDate.set(Calendar.DATE, 1);// 设为当前月的1号
lastDate.add(Calendar.MONTH, -1);// 减一个月,变为下月的1号
str = format(lastDate.getTime(),yyyy_MM_dd);
return str;
}
/**
*
* 获得当前时间
* @return Date
*/
public static Date getSystemTime() {
Calendar now = Calendar.getInstance();
return now.getTime();
}
/**
*
* 获得系统时间 格式根据系统默认格式
* @return String
*/
case 2:type2List.add(paperDetail);break;
case 3:type3List.add(paperDetail);break;
case 4:type4List.add(paperDetail);break;
}
}
for(int i=0;i<type1List.size();i++){
type1List.get(i).setField0((i+1)+"");
}
for(int i=0;i<type2List.size();i++){
int j = type1List.size() + i + 1;
type2List.get(i).setField0(j+"");
}
for(int i=0;i<type3List.size();i++){
int j = type1List.size() +type2List.size()+ i + 1;
type3List.get(i).setField0(j+"");
}
for(int i=0;i<type4List.size();i++){
int j = type1List.size() +type2List.size()+type3List.size()+ i + 1;
type4List.get(i).setField0(j+"");
import javax.servlet.http.HttpServletRequest;
import java.io.*;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.UUID;
/**
* Created by jianggc
*/
@Api(tags = {"文件管理"})
@Controller
@RequestMapping({"file","ueditor","/app/file"})
public class FileController {
private static final Logger logger= LoggerFactory.getLogger(FileController.class);
@Autowired
private SysFileService fileService;
@Value("${com.jane.file.baseFilePath}")
*
* 日期的字符串格式转Date对象实例
* @param strdate 日期
* @param pattern 日期格式
* @return Date
*/
public static Date parseDate(String strdate, String pattern) {
Date date=null;
if (StringUtils.isEmpty(pattern)) {
pattern = yyyy_MM_dd_HH_mm_ss;
}
try {
if (!StringUtils.isEmpty(strdate)) {
SimpleDateFormat sdf = new SimpleDateFormat(pattern);
date = sdf.parse(strdate);
}
} catch (ParseException e) {
log.error("parseDate(String date, String pattern) ", e);
e.printStackTrace();
}
return date;
}
public static Date parseDate(String strdate) {
Date date=null;
try {
/**
* 考试提交试卷后自动计算选择题分数
* `single_score` '单选得分',
* `multiple_score` '多选得分',
*/
private void checkChooseScore(UserPaper userPaper,Long userId,Long paperId){
String singleScore = dictValueService.getValueByCode("single_score").get(0).getDictValue();//单选题分值
String multipleScore = dictValueService.getValueByCode("multiple_score").get(0).getDictValue();//多选题分值
QueryWrapper<UserPaperDetail> queryWrapper=new QueryWrapper<>();
queryWrapper.eq("user_id",userId);
queryWrapper.eq("paper_id",paperId);
queryWrapper.and(e->e.eq("question_type",1).or().eq("question_type",2));
List<UserPaperDetail> userPaperDetailList = userPaperDetailService.list(queryWrapper);
float singleNum=0;//单选题得分
float multipleNum=0;//多选题得分
for(UserPaperDetail userPaperDetail:userPaperDetailList){
if(userPaperDetail.getRighterAnswer().equals(userPaperDetail.getUserAnswer())&&userPaperDetail.getQuestionType()==1){
singleNum+=Float.parseFloat(singleScore);
}
if(userPaperDetail.getRighterAnswer().equals(userPaperDetail.getUserAnswer())&&userPaperDetail.getQuestionType()==2){
multipleNum+=Float.parseFloat(multipleScore);
}
}
userPaper.setSingleScore(singleNum);
userPaper.setMultipleScore(multipleNum);
}
package com.demo.common;
import com.alibaba.fastjson.JSONObject;
import com.sun.net.httpserver.HttpExchange;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.apache.http.HttpEntity;
import org.apache.http.HttpHost;
import org.apache.http.NameValuePair;
import org.apache.http.client.entity.UrlEncodedFormEntity;
var contentVal=val.answerc;
if(contentVal&&contentVal.length>30){
return '<a title="点击查看详情" onclick="showContent(\''+contentVal+'\')" href="javascript:void(0);">'+contentVal+'</a>'
}else{
return contentVal==null?"":contentVal;;
}
}}
,{field:'answerd', title: '选项D', align:'center',templet:function (val) {
var contentVal=val.answerd;
if(contentVal&&contentVal.length>30){
return '<a title="点击查看详情" onclick="showContent(\''+contentVal+'\')" href="javascript:void(0);">'+contentVal+'</a>'
}else{
return contentVal==null?"":contentVal;;
}
}}
,{field:'righterAnswer', title: '正确答案', align:'center',templet:function (val) {
var contentVal=val.righterAnswer;
byte[] r = new byte[limit];
buffer.flip();
buffer.get(r);
return r;
}
}
}
return null;
}
public static long getFormInfo(BufferedInputStream bis, Map<String, String> ret_map) throws IOException {
ByteBuffer buffer = ByteBuffer.allocate(1024);
icon: 1, time: 1500
},function () {
$(".layui-form-checked").not('.header').parents('tr').remove();
$(".layui-unselect.header.layui-form-checkbox.layui-form-checked").attr("class","layui-unselect header layui-form-checkbox");
table.reload('test-table-reload', {
page: {
curr: 1 //重新从第 1 页开始
}
,where: $('#search-form').parseForm()
});
});
}
});
});
}
function showContent(content) {
layer.open({
title: "信息详情",
offset: ['25%', '25%'],
type: 1,
order: ['auto', '55%'], //宽高
shadeClose: true,//点击遮罩关闭
content: "<div style='min-height: 200px;min-width:300px;text-align: center'>"+content+"</div>"
});
}
</script>
@RequestMapping("/listPage")
public String listPage(Integer type,Model model) {
model.addAttribute("type",type);
if(type!=null&&type==1){
return prefix+"list1";//学生考试试卷列表
}
return prefix+"list2";//学生试卷列表
}
/**
* 分页列表查询
* @param queryParam 查询参数
* @return
*/
@RequestMapping("/list")
@ResponseBody
public ResponseBean getList(PageDTO pageDTO, UserPaper queryParam , HttpSession session) {
logger.debug("查询学生试卷考试试卷列表参数:"+queryParam+",pageDTO:"+pageDTO);
QueryWrapper<UserPaper> queryWrapper=new QueryWrapper<>();
queryWrapper.like(!StringUtils.isEmpty(queryParam.getField4()),"field4",queryParam.getField4());
queryWrapper.eq(queryParam.getState()!=null,"state",queryParam.getState());
queryWrapper.eq(queryParam.getType()!=null,"type",queryParam.getType());
queryWrapper.eq(queryParam.getUserId()!=null,"user_id",queryParam.getUserId());
queryWrapper.eq(queryParam.getPaperId()!=null,"paper_id",queryParam.getPaperId());
stringBuffer.append("A");
}
if(!StringUtils.isEmpty(checkVal)&&checkVal.contains("B")){
stringBuffer.append("B");
}
if(!StringUtils.isEmpty(checkVal)&&checkVal.contains("C")){
stringBuffer.append("C");
}
if(!StringUtils.isEmpty(checkVal)&&checkVal.contains("D")){
stringBuffer.append("D");
}
userPaperDetail.setUserAnswer(stringBuffer.toString());
break;
case 3:
case 4: userPaperDetail.setUserAnswer(userAnswer);break;