package cn.xxn.ctest.student.dao;
import java.util.ArrayList;
import java.util.List;
import org.springframework.orm.hibernate5.HibernateCallback;
import org.springframework.orm.hibernate5.support.HibernateDaoSupport;
import cn.xxn.ctest.answerstate.entity.AnswerState;
import cn.xxn.ctest.bj.entity.BJ;
import cn.xxn.ctest.question.entity.Question;
import cn.xxn.ctest.questionpaper.entity.QuestionPaper;
import cn.xxn.ctest.student.entity.Students;
import cn.xxn.ctest.teacheruser.entity.Teacher;
import cn.xxn.ctest.testnote.entity.TestNote;
import cn.xxn.ctest.utils.PageHibernateCallback;
public class StudentDao extends HibernateDaoSupport{
//查询学生是否存在
public Students login(Students student) {
String hql = "from Students where sid = ? and password = ?";
List<Students> list = (List<Students>) this.getHibernateTemplate().find(hql, student.getSid(),student.getPassword());
if(list != null && list.size() > 0){
return list.get(0);
}
return null;
}
//根据教师编号查询总的记录数
public int findCountTid(Integer tid) {
String hql = "select count(*) from Students s where s.bj.teacher.tid= ? ";
List<Long> list = (List<Long>) this.getHibernateTemplate().find(hql, tid);
if(list != null && list.size()>0){
return list.get(0).intValue();
}
return 0;
}
public int findCountAdmin() {
String hql = "select count(*) from Students ";
List<Long> list = (List<Long>) this.getHibernateTemplate().find(hql,null);
if(list != null && list.size()>0){
return list.get(0).intValue();
}
return 0;
}
//根据教师编号查询学生信息集合
public List<Students> findByPageTid(Integer tid, int begin, int limit) {
//SELECT s.* from teacheruser t, bj b, student s where t.tid = b.tid and b.bjid = s.bjid and t.tid = 1542110250
String hql = "select s from Students s join s.bj b join b.teacher t where t.tid = ? order by s.sid";
//分页实现
List<Students> list = this.getHibernateTemplate().execute(new PageHibernateCallback<Students>(hql, new Object[]{tid}, begin, limit));
List<Students> liststu = new ArrayList<Students>();
String hql2 = null;
for(int i=0; i<list.size();i++){
Students stu = list.get(i);
hql2 = "from BJ where bjid = ?";
List<BJ> listbj = (List<BJ>) this.getHibernateTemplate().find(hql2, list.get(i).getBj().getBjid());
if(listbj!=null && listbj.size()>0){
stu.setBj(listbj.get(0));
}
liststu.add(stu);
}
return liststu;
}
public List<Students> findByPageAdmin(int begin, int limit) {
String hql = "select s from Students s order by s.sid";
//分页实现
List<Students> list = this.getHibernateTemplate().execute(new PageHibernateCallback<Students>(hql, new Object[]{}, begin, limit));
List<Students> liststu = new ArrayList<Students>();
String hql2 = null;
for(int i=0; i<list.size();i++){
Students stu = list.get(i);
hql2 = "from BJ where bjid = ?";
List<BJ> listbj = (List<BJ>) this.getHibernateTemplate().find(hql2, list.get(i).getBj().getBjid());
if(listbj!=null && listbj.size()>0){
stu.setBj(listbj.get(0));
}
liststu.add(stu);
}
return liststu;
}
//查询所有班级
public List<BJ> ckbj(Integer tid) {
String hql = "from BJ where tid = ?";
List<BJ> list = (List<BJ>) this.getHibernateTemplate().find(hql, tid);
return list;
}
public List<BJ> ckbjAdmin() {
String hql = "from BJ";
List<BJ> list = (List<BJ>) this.getHibernateTemplate().find(hql, null);
return list;
}
public Students finBySid(Integer sid) {
String hql = "from Students where sid = ?";
List<Students> list = (List<Students>) this.getHibernateTemplate().find(hql, sid);
if(list!=null && list.size()>0){
return list.get(0);
}
return null;
}
//添加学生信息
public void addStudentSX(Students student, Integer bjid) {
String hql = "from BJ where bjid = ?";
List<BJ> list = (List<BJ>) this.getHibernateTemplate().find(hql, bjid);
BJ bj = null;
if(list!=null && list.size()>0){
bj = list.get(0);
}
student.setBj(bj);
this.getHibernateTemplate().save(student);
}
//根据学号删除学生
public void deleteStudent(Integer sid) {
String hql2 = "from Students where sid = ?";
List<Students> liststu = (List<Students>) this.getHibernateTemplate().find(hql2, sid);
this.getHibernateTemplate().delete(liststu.get(0));
}
//根据学号查询学生信息
public List<TestNote> ckTestNote(Integer sid) {
String hql = "from TestNote tn where tn.students.sid = ? order by tn.tnid desc";
String hql2 = null;
Integer score = null ;
Integer scorexz = null;
Integer scoretk = null;
Integer scorepd = null;
List<TestNote> listtn = (List<TestNote>) this.getHibernateTemplate().find(hql, sid);
List<TestNote> list = new ArrayList<TestNote>();
for(int i=0; i<listtn.size(); i++){
TestNote tn = listtn.get(i);
hql2 = "select count(*) from AnswerState a where a.testNote.tnid = ? and a.state = ? and a.question.questionType.qtid = ?";
List<Long> listlongxz = (List<Long>) this.getHibernateTemplate().find(hql2, listtn.get(i).getTnid(),1,1);
if(listlongxz != null && listlongxz.size()>0){
scorexz = listlongxz.get(0).intValue()*2;
}
List<Long> listlongpd = (List<Long>) this.getHibernateTemplate().find(hql2, listtn.get(i).getTnid(),1,2);
if(listlongpd != null && listlongpd.size()>0){
scorepd = listlongpd.get(0).intValue();
}
List<Long> listlongtk = (List<Long>) this.getHibernateTemplate().find(hql2, listtn.get(i).getTnid(),1,3);
if(listlongtk != null && listlongtk.size()>0){
scoretk = listlongtk.get(0).intValue()*2;
}
score = scorexz+scorepd+scoretk;
tn.setScore(score);
this.getHibernateTemplate().save(tn);
list.add(tn);
}
return list;
}
//根据考试记录编号查询选择题
public List<AnswerState> ckAnserStatexz(Integer tnid) {
String hql = "from AnswerState a where a.testNote.tnid = ? and a.question.questionType.qtid = ? order by a.anid asc";
String hql2 = null;
List<AnswerState> listas = (List<AnswerState>) this.getHibernateTemplate().find(hql, tnid, 1);
List<AnswerState> list = new ArrayList<AnswerState>();
for(int i=0; i<listas.size(); i++){
AnswerState a = listas.get(i);
hql2 = "from Question where qid = ?";
List<Question> listq = (List<Question>) this.getHibernateTemplate().find(hql2, listas.get(i).getQuestion().getQid());
if(listq != null && listq.size() > 0 ){
a.setQuestion(listq.get(0));
}
list.add(a);
}
return list;
}
//根据考试记录编号查询判断题
public List<AnswerState> ckAnserStatepd(Integer tnid) {
String hql = "from AnswerState a where a.testNote.tnid = ? and a.question.questionType.qtid = ? order by a.anid asc";
String hql2 = null;
List<AnswerState> listas = (List<AnswerState>) this.getHibernateTemplate().find(hql, tnid, 2);
List<AnswerState> list = new ArrayList<AnswerState>();
for(int i=0; i<listas.size(); i++){
AnswerState a = listas.get(i);
hql2 = "from Question where qid = ?";
List<Question> listq = (List<Question>) this.getHibernateTemplate().find(hql2, listas.get(i).getQuestion().getQid());
if(listq != null && listq.size() > 0 ){
a.setQuestion(listq.get(0));
}
list.add(a);
}
return list;
}
//根据考试记录编号查询填空题
public List<AnswerState> ckAnserStatetk(Integer tnid) {
String hql = "from AnswerState a where a.testNote.tnid = ? and a.question.questionType.qtid = ? order by a.anid asc";
String hql2 = null;
List<AnswerState> listas = (List<AnswerState>) this.getHibernateTemplate().find(hql, tnid, 3);
List<AnswerState> list = new ArrayList<AnswerState>();
for(int i=0; i<listas.size(); i++){
AnswerState a = listas.get(i);
hql2 = "from Question where qid = ?";
List<Question> listq = (List<Question>) this.getHibernateTemplate().find(hql2, listas.get(i).getQuestion().getQid());
if(listq != null && listq.size() > 0 ){
a.setQuest
没有合适的资源?快使用搜索试试~ 我知道了~
资源推荐
资源详情
资源评论
收起资源包目录
基于web的在线考试系统的设计与实现,一整套,工程,数据库文件,word,ppt,直接运行 (284个子文件)
StudentDao.class 11KB
TestControlDao.class 8KB
QuestionPaperDao.class 7KB
QuestionAction.class 7KB
StudentAction.class 7KB
QuestionDao.class 7KB
QuestionPaperAction.class 6KB
TestControlAction.class 6KB
TeacherAction.class 5KB
QuestionPaperService.class 5KB
StudentService.class 5KB
TestControlService.class 4KB
Question.class 4KB
QuestionService.class 4KB
BJAction.class 4KB
BJDao.class 4KB
AdminUserAction.class 3KB
TestNote.class 3KB
TeacherDao.class 3KB
QuestionPaper.class 3KB
AnswerStateDao.class 2KB
Teacher.class 2KB
Students.class 2KB
AnswerStateService.class 2KB
AnswerStateAction.class 2KB
BJService.class 2KB
AdminUserDao.class 2KB
PageHibernateCallback.class 2KB
TestControl.class 2KB
TeacherService.class 2KB
PageBean.class 2KB
BJ.class 2KB
TestNoteAction.class 2KB
QuestionType.class 2KB
TestNoteDao.class 1KB
QpRelationq.class 1KB
AnswerState.class 1KB
TestNoteService.class 1KB
QuestionTypeAction.class 1KB
QpRelationqAction.class 1KB
AdminUserService.class 1KB
AdminUser.class 1018B
QuestionTypeService.class 667B
QpRelationqService.class 662B
QuestionTypeDao.class 376B
QpRelationqDao.class 371B
.classpath 4KB
org.eclipse.wst.common.component 450B
org.eclipse.wst.jsdt.ui.superType.container 49B
bootstrap.min.css 118KB
font-awesome.min.css 30KB
htmleaf-demo.css 6KB
normalize.css 2KB
部署要点.doc 205KB
在线考试系统.docx 2.04MB
icomoon.eot 2KB
index.html 7KB
index.html 7KB
readme.html 865B
hibernate-core-5.0.7.Final.jar 5.32MB
aspectjweaver-1.8.7.jar 1.78MB
freemarker-2.3.22.jar 1.24MB
spring-context-4.2.4.RELEASE.jar 1.05MB
spring-core-4.2.4.RELEASE.jar 1.03MB
struts2-core-2.3.24.jar 812KB
log4j-core-2.3.jar 808KB
spring-web-4.2.4.RELEASE.jar 749KB
spring-beans-4.2.4.RELEASE.jar 714KB
javassist-3.18.1-GA.jar 697KB
mysql-connector-java-5.1.7-bin.jar 693KB
xwork-core-2.3.24.jar 661KB
c3p0-0.9.1.2.jar 596KB
hibernate-entitymanager-5.0.7.Final.jar 584KB
mchange-commons-java-0.2.3.4.jar 568KB
log4j-1.2.16.jar 470KB
spring-orm-4.2.4.RELEASE.jar 455KB
antlr-2.7.7.jar 435KB
spring-jdbc-4.2.4.RELEASE.jar 413KB
commons-lang3-3.2.jar 376KB
spring-aop-4.2.4.RELEASE.jar 361KB
dom4j-1.6.1.jar 307KB
spring-tx-4.2.4.RELEASE.jar 259KB
spring-expression-4.2.4.RELEASE.jar 257KB
ognl-3.0.6.jar 223KB
jandex-2.0.0.Final.jar 183KB
commons-io-2.2.jar 170KB
log4j-api-2.3.jar 133KB
hibernate-jpa-2.1-api-1.0.0.Final.jar 111KB
hibernate-commons-annotations-5.0.1.Final.jar 74KB
commons-fileupload-1.3.1.jar 67KB
jboss-logging-3.3.0.Final.jar 65KB
commons-logging-1.1.3.jar 61KB
spring-aspects-4.2.4.RELEASE.jar 57KB
asm-3.3.jar 43KB
asm-commons-3.3.jar 37KB
slf4j-api-1.6.1.jar 25KB
struts2-spring-plugin-2.3.24.1.jar 21KB
asm-tree-3.3.jar 21KB
geronimo-jta_1.1_spec-1.1.1.jar 16KB
slf4j-log4j12-1.7.2.jar 9KB
共 284 条
- 1
- 2
- 3
资源评论
xxq121389527
- 粉丝: 323
- 资源: 42
下载权益
C知道特权
VIP文章
课程特权
开通VIP
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功