学生在线考试系统项目设计文档_第1页
学生在线考试系统项目设计文档_第2页
学生在线考试系统项目设计文档_第3页
学生在线考试系统项目设计文档_第4页
学生在线考试系统项目设计文档_第5页
已阅读5页,还剩22页未读 继续免费阅读

下载本文档

版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领

文档简介

1、四川交通职业技术学院信息工程系项目设计文档题 目:学生在线考试系统班 级 软件13-1 学 号 20131645、20132907、20132185、20132266 姓 名 姜维川、郑雨云、侯鉴航、邓凯 任课教师 吉朝明 二O一五 年 6 月目录1 需求描述32 系统功能描述32.1 系统功能图32.2 系统主流程图33 数据库设计54 界面原型设计55 类设计66 关键代码88 项目总结249程序错误报告2510参考文献25学生在线考试系统文档1 需求描述该系统主要是由前台学生端和后台教师端两部分组成。前台学生端即是学生通过在线考试后得到分数,后台教师端即是对试卷和学生的信息进行管理。2

2、系统功能描述2.1 系统功能图系统功能图如图1所示。图1 系统功能图2.2 系统主流程图系统主流程图如图2所示。图2 系统主流程图3 数据库设计本系统选择Mysql数据库,建立名为testsystem.mdb的数据库,涉及到主要的数据库表设计如表1-表2-表3所示。表1 test字段名字段类型可否为空说明idINT(10)Not null主键testidINT(10)Not nullsidINT(10)NULLcontenttextNot nullgradeINT(10)Not nullansweridINT(10)Not null表2 answer字段名字段类型可否为空说明idINT(10)

3、Not null主键tidINT(10)Not nullcontenttextNot null表3 student字段名字段类型可否为空说明idINT(10)Not null主键uidINT(10)Not nullnamevarchar(30)Not nullprofessionalIdINT(10)Not nulldepartmentINT(10)Not nullxhINT(10)Not nullsexvarchar(30)Not nulltikeIdINT(10)Not nullageINT(10)Not null4 界面原型设计1. 前台首页2. 后台首页5 类设计本系统设计了actio

4、n、Aspect、dao、filter、model、service六个类,具体说明及相关类代码如下:(1) action类action+TestAction( )+userAction( )(2) Aspect类Aspect+LogAspect( )(3)dao类dao+AnswerDao( )+DepartMentDao( )+GradeDao( )+ProfessionalDao( )+SubjectDao( )+TestDao( )+UserDao( )(4)filter类filter+MyFilter( )(5) model类model+Answer( )+Department( )+

5、Grade( )+GradeJSon( )+Loganderror( )+Professional( )+Student( )+StudentJson( )+Subject( )+Test( )+Users( )(6) service类Service+AnswerManage( )+DepartmentManage( )+Factory( )+GradeManage( )+ProfessionalManage( )+SubjectManage( )+TestManage( )+UserManagerImp( )6 关键代码(1)获取及更新题目答案package com.test.dao;imp

6、ort java.util.List;import org.hibernate.Query;import org.hibernate.Session;import org.hibernate.SessionFactory;import org.hibernate.Transaction;import org.hibernate.cfg.Configuration;import org.hibernate.service.ServiceRegistry;import org.hibernate.service.ServiceRegistryBuilder;import com.test.mode

7、l.Answer;import com.test.model.Department;public class AnswerDaoImp implements AnswerDaoprivate SessionFactory sessionFactory;private Session sess;private Transaction transaction;private void createsession()sess=sessionFactory.openSession();transaction=sess.beginTransaction();private void destory()m

8、it();sess.close();sessionFactory.close();public AnswerDaoImp() Configuration configuration=new Configuration();configuration.configure();ServiceRegistry serviceRegistry=new ServiceRegistryBuilder().applySettings(configuration.getProperties().buildServiceRegistry();SessionFactory sessionFactory=confi

9、guration.buildSessionFactory(serviceRegistry);/为当前的sessionFactory赋值this.sessionFactory=sessionFactory;Overridepublic List<Answer> getanswers() Session session=sessionFactory.openSession();Query query=session.createQuery("from Answer");List<Answer> answers=query.list();session.c

10、lose();return answers;Overridepublic List<Answer> getAnswersBytid(int tid) Session session=sessionFactory.openSession();Query query=session.createQuery("from Answer where test.id="+tid);List<Answer> answers=query.list();session.close();return answers;Overridepublic Answer getAn

11、swerById(int id) Session session=sessionFactory.openSession();Query query=session.createQuery("from Answer d where d.id="+id);List<Answer> answers=query.list();if(answers.size()>0)session.close();return answers.get(0);return null;Overridepublic boolean saveanswer(Answer answer) tr

12、y createsession();sess.save(answer);mit();destory();return true; catch (Exception e) / TODO: handle exceptionreturn false;Overridepublic boolean updateanswer(Answer answer) try createsession();sess.update(answer);destory();return true; catch (Exception e) / TODO: handle exceptionreturn false;Overrid

13、epublic boolean deleteanswer(Answer answer) createsession();String sql="delete from Answer where id="+answer.getId();Query query=sess.createQuery(sql);if(query.executeUpdate()!=0)destory();return true;return false;(2)测试package com.test.dao;import java.util.ArrayList;import java.util.HashSe

14、t;import java.util.List;import java.util.Set;import net.sf.json.JSONArray;import net.sf.json.JSONObject;import org.aspectj.weaver.ast.And;import org.hibernate.Query;import org.hibernate.Session;import org.hibernate.SessionFactory;import org.hibernate.Transaction;import org.hibernate.cfg.Configuratio

15、n;import org.hibernate.service.ServiceRegistry;import org.hibernate.service.ServiceRegistryBuilder;import com.test.model.Answer;import com.test.model.Subject;import com.test.model.Test;import com.test.service.Factory;public class TestDaoImp implements TestDaoprivate SessionFactory sessionFactory;pri

16、vate Session sess;private Transaction transaction;private void createsession()sess=sessionFactory.openSession();transaction=sess.beginTransaction();private void destory()mit();sess.close();sessionFactory.close();public TestDaoImp() Configuration configuration=new Configuration();configuration.config

17、ure();ServiceRegistry serviceRegistry=new ServiceRegistryBuilder().applySettings(configuration.getProperties().buildServiceRegistry();SessionFactory sessionFactory=configuration.buildSessionFactory(serviceRegistry);/为当前的sessionFactory赋值this.sessionFactory=sessionFactory;Overridepublic List<Test&g

18、t; getTestBySid(int sid) Session session=sessionFactory.openSession();Query query;if(sid=-1)query=session.createQuery("from Test");else query=session.createQuery("from Test where subject.id="+sid);List<Test> tests=query.list();session.close();return tests;Overridepublic JSO

19、NArray getTestBySidJson(int sid)Session session=sessionFactory.openSession();Query query;if(sid=-1)query=session.createQuery("from Test");else query=session.createQuery("from Test where subject.id="+sid);List<Test> tests=query.list();JSONObject jsonObject;List<Test> a

20、lltest=new ArrayList<Test>();for (Test test : tests) Set<Answer> answers = new HashSet();/List<Answer> listanswers=Factory.getAnswerManage().getAnswersBytid(test.getId();Set<Answer> currentanswer=test.getAnswers();for (Answer answer : currentanswer) answer.setTest(null);answe

21、rs.add(answer);test.setAnswers(answers);test.setSubject(null);alltest.add(test);JSONArray jsonArray=new JSONArray().fromObject(tests);session.close();return jsonArray;Overridepublic List<Test> getTest() / TODO Auto-generated method stubreturn null;Overridepublic boolean saveTest(Test test) / T

22、ODO Auto-generated method stubreturn false;Overridepublic boolean updateTest(Test test) / TODO Auto-generated method stubreturn false;Overridepublic boolean deleteTest(Test test) / TODO Auto-generated method stubreturn false;(3) 用户操作package com.test.dao;import java.util.ArrayList;import java.util.Li

23、st;import org.hibernate.Query;import org.hibernate.Session;import org.hibernate.SessionFactory;import org.hibernate.Transaction;import org.hibernate.cfg.Configuration;import org.hibernate.service.ServiceRegistry;import org.hibernate.service.ServiceRegistryBuilder;import com.test.model.Department;imp

24、ort com.test.model.Professional;import com.test.model.Student;import com.test.model.StudentJson;import com.test.model.Users;import com.test.service.Factory;public class UserDaoImp implements UserDaoprivate SessionFactory sessionFactory;private Session sess;private Transaction transaction;private voi

25、d createsession()sess=sessionFactory.openSession();transaction=sess.beginTransaction();private void destory()mit();sess.close();sessionFactory.close();public UserDaoImp()Configuration configuration=new Configuration();configuration.configure();ServiceRegistry serviceRegistry=new ServiceRegistryBuild

26、er().applySettings(configuration.getProperties().buildServiceRegistry();SessionFactory sessionFactory=configuration.buildSessionFactory(serviceRegistry);/为当前的sessionFactory赋值this.sessionFactory=sessionFactory;Overridepublic boolean select_user(Users user) System.out.println("开始执行查找用户操作");C

27、onfiguration configuration=new Configuration();configuration.configure();ServiceRegistry serviceRegistry=new ServiceRegistryBuilder().applySettings(configuration.getProperties().buildServiceRegistry();SessionFactory sessionFactory=configuration.buildSessionFactory(serviceRegistry);Session session=se

28、ssionFactory.openSession();/Transaction transaction=session.beginTransaction();String sql=" from Users as u where u.loginId='"+user.getLoginId()+"' and u.loginPwd='"+user.getLoginPwd()+"' and u.role='"+user.getRole()+"'"System.out.print

29、ln(sql);Query query=session.createQuery(sql);List<Users> alluser=query.list();/System.out.println(alluser);if(alluser.size()>0)System.out.println("找到有用户");session.close();return true;elseSystem.out.println("没有找到有用户");return false;Overridepublic Student select_studentByUi

30、d(int uid) System.out.println("开始根据用户的Id查找学生了");Session session=sessionFactory.openSession();String hsql="from Student as s where s.uid="+uid;System.out.println(hsql);Query query=session.createQuery(hsql);Student student=null;List<Student> students=query.list();session.clos

31、e();if(students.size()>0)student=students.get(0);return student;elsereturn student;Overridepublic Users getUserByLoginId(String LoginId) Session session=sessionFactory.openSession();String sql=" from Users as u where u.loginId='"+LoginId+"'"System.out.println(sql);Quer

32、y query=session.createQuery(sql);List<Users> alluser=query.list();if(alluser.size()>0)System.out.println("找到有用户");session.close();return alluser.get(0);elsereturn null;Overridepublic boolean updateStudent(Student student) try createsession();sess.update(student);destory();return t

33、rue; catch (Exception e) / TODO: handle exceptionreturn false;Overridepublic int saveUsers(Users user) int uid=-1;try createsession();sess.save(user);uid=user.getId();destory();return uid; catch (Exception e) / TODO: handle exceptionreturn uid;Overridepublic int saveStudent(Student student) int id=-

34、1;try createsession();sess.save(student);id=student.getId();destory();return id; catch (Exception e) / TODO: handle exceptionreturn id;Overridepublic List<Student> getAllStudents() Session session=sessionFactory.openSession();String sql=" from Student"System.out.println(sql);Query qu

35、ery=session.createQuery(sql);List<Student> alluser=query.list();if(alluser.size()>0)System.out.println("找到有学生");session.close();return alluser;elsereturn null;Overridepublic List<StudentJson> getAllstudentJson() createsession();String sql=" from Student"System.out.

36、println(sql);Query query=sess.createQuery(sql);List<Student> alluser=query.list();List<StudentJson> studentJsons=new ArrayList<StudentJson>();if(alluser.size()>0)for(Student student:alluser)StudentJson studentJson=new StudentJson();studentJson.setAge(student.getAge().toString();

37、Department department=Factory.getDepartmentManage().getDepartMentById(student.getDepartment();Professional professional=Factory.getProfessionalManage().getProFeProfessionalById(student.getProfessionalId();studentJson.setDepartment(department.getDname();studentJson.setId(student.getId();studentJson.s

38、etName(student.getName();studentJson.setProfessional(professional.getPname();studentJson.setSex(student.getSex();studentJson.setXh(student.getXh();studentJsons.add(studentJson);destory();return studentJsons;elsereturn null;(4) 获取分数package com.test.dao;import java.util.ArrayList;import java.util.List

39、;import net.sf.json.JSONArray;import net.sf.json.JsonConfig;import org.hibernate.Query;import org.hibernate.Session;import org.hibernate.SessionFactory;import org.hibernate.Transaction;import org.hibernate.cfg.Configuration;import org.hibernate.service.ServiceRegistry;import org.hibernate.service.Se

40、rviceRegistryBuilder;import com.test.model.Grade;import com.test.model.GradeJSon;import com.test.model.Professional;import com.test.model.Student;import com.test.model.Subject;import com.test.service.Factory;public class GradeDaoImp implements GradeDaoprivate SessionFactory sessionFactory;private Se

41、ssion sess;private Transaction transaction;private void createsession()sess=sessionFactory.openSession();transaction=sess.beginTransaction();private void destory()mit();sess.close();sessionFactory.close();public GradeDaoImp() Configuration configuration=new Configuration();configuration.configure();

42、ServiceRegistry serviceRegistry=new ServiceRegistryBuilder().applySettings(configuration.getProperties().buildServiceRegistry();SessionFactory sessionFactory=configuration.buildSessionFactory(serviceRegistry);/为当前的sessionFactory赋值this.sessionFactory=sessionFactory;Overridepublic Grade getGradeByid(i

43、nt id) Session session=sessionFactory.openSession();Query query=session.createQuery("from Grade g where g.id="+id);List<Grade> grades=query.list();if(grades.size()>0)session.close();return grades.get(0);return null;Overridepublic List<Grade> getGradeByUid(int uid) System.out

44、.println("开始根据用户的id来查找了"+uid);createsession();Query query;if(uid=-1)query=sess.createQuery("from Grade");else query=sess.createQuery("from Grade where student.uid="+uid);List<Grade> grades=query.list();for (Grade grade : grades) System.out.println(grade.getId();Sy

45、stem.out.println(grade.getSubject().getName();System.out.println(grade.getStudent().getUid();destory();return grades;Overridepublic boolean saveGrade(Grade grade) try createsession();sess.save(grade);destory();return true; catch (Exception e) System.out.println(e.getMessage();return false;Overridepu

46、blic boolean deleteGradeByid(int id) createsession();String sql="delete from Grade where id="+id;Query query=sess.createQuery(sql);if(query.executeUpdate()!=0)destory();return true;return false;Overridepublic boolean updateSubject(Grade grade) try createsession();sess.update(grade);destory

47、();return true; catch (Exception e) / TODO: handle exceptionreturn false;Overridepublic List<Grade> getGradeBySid(int sid) Session session=sessionFactory.openSession();Query query;if(sid=-1)query=session.createQuery("from Grade");else query=session.createQuery("from Grade where subject.id="+sid);List<Grade> grades=query.list();session.close();return grades;Overridepublic List<GradeJSon> getAllGradeJSON() Session session=sessionFactory.openSession();Query query=session.createQuery("from Grade");List<Grade> gr

温馨提示

  • 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
  • 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
  • 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
  • 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
  • 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
  • 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
  • 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

评论

0/150

提交评论