mysql数据库随机_mysql数据库随机生成某个范围内的数据

论坛 期权论坛 编程之家     
选择匿名的用户   2021-6-1 19:10   87   0

一、完成内容

1. 根据组卷规则随机生成试题

2. 获取考生答案,计算分数

3. 判断答案正误,错题存到错题表

4. 判断考试是否第一次答题,若不是,使用第一次生成的试题

二、功能截图

3e3348ce4d0d7d095a1c3513ccc46b3f.png

bbc6db04ba9b377a553c7f22ab63a062.png

81dbffd484be953dd32b7f574488ba55.png

d63a01fcbe3e72352bbd902b742fe35e.png

三、核心代码

/**

* @param context 页面传过来的题号及其对应的答案,形式是 题号:ABCD*/@OverridepublicInteger stuTest(String testId, String context, String stuname) {//TODO Auto-generated method stub//声明一个变量分数

int rightNum =0;

String bids="";//处理答案,计算分数//1.处理文本

String str[] = context.split(",");for (int i = 0; i < str.length; i++) {//获取对应的试题id

String bid = str[i].substring(0, str[i].indexOf(":"));//获取对应答案

String answer= str[i].substring(str[i].indexOf(":")+1);//根据bid查询出题库中正确的答案

ItemBank itemBank = itemBankDao.selectByBid(newInteger(bid));//判断答案是否一致

answer = answer.replaceAll(" ", "");

String itemBankAnswer= itemBank.getAnswer().replace(" ", "");if(answer.equalsIgnoreCase(itemBankAnswer)) {

rightNum=rightNum+1;

System.out.println("rightNum>>>"+rightNum);

}else{//查询判断是否含有此bid

MisCollection collection = misCollectionDao.selectByStuname(newInteger(stuname));if(collection!=null) {

String misbids=collection.getBids();if(!misbids.contains(bid)) {

misbids+=","+bid;

misCollectionDao.update(misbids,newInteger(stuname));

}

}else{//第一次做题

if(i==0) {

bids=bid;

}else{

bids+=","+bid;

}//将错题存到表中

misCollectionDao.add(bids,newInteger(stuname));

}

}

}

Double score= (double)((rightNum/str.length)*100);//将分数,答案更新到试卷表(testpaper)

return testPaperDao.updateScoreAndAnswer(score,context,new Integer(testId),newInteger(stuname));

}

四、数据库随机范围查询

SELECT * FROM itembank

WHERE bid >= (SELECT floor((select MIN(bid) from itembank where subid=#{0})+RAND() * (SELECT MAX(bid) FROM itembank where subid=#{0})))

ORDER BY bid LIMIT #{1}

分享到 :
0 人收藏
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

积分:3875789
帖子:775174
精华:0
期权论坛 期权论坛
发布
内容

下载期权论坛手机APP