📄 examserviceimpl.java
字号:
package com.lili.exam.service;
import java.util.List;
import com.lili.common.exception.ExamException;
import com.lili.exam.dao.ExamDao;
import com.lili.exam.dao.ExamDaoImpl;
import com.lili.exam.pojo.CChoice;
import com.lili.exam.pojo.SelectOne;
import com.lili.exam.pojo.Student;
import com.lili.exam.pojo.Subject;
import com.lili.exam.pojo.Teacher;
import com.lili.exam.util.BeanFactory;
public class ExamServiceImpl implements ExamService{
public Student getStudentByName(String name) throws ExamException {
ExamDao dao = (ExamDaoImpl) BeanFactory.getBean("examDao");
try {
Student stu = dao.getStudentByName(name);
return stu;
} catch (Exception e) {
e.printStackTrace();
throw new ExamException(e.getMessage());
}
}
public Teacher getTeacherByName(String name) throws ExamException{
ExamDao dao = (ExamDaoImpl) BeanFactory.getBean("examDao");
try {
Teacher tea = dao.getTeacherByName(name);
return tea;
} catch (Exception e) {
e.printStackTrace();
throw new ExamException(e.getMessage());
}
}
public void savaOrUpdateTeacher(Teacher teacher) throws ExamException{
ExamDao dao = (ExamDaoImpl) BeanFactory.getBean("examDao");
try {
dao.savaOrUpdateTeacher(teacher);
} catch (Exception e) {
e.printStackTrace();
throw new ExamException(e.getMessage());
}
}
public void saveOrUpdateChoice(CChoice choice) throws ExamException{
ExamDao dao = (ExamDaoImpl) BeanFactory.getBean("examDao");
try {
dao.saveOrUpdateChoice(choice);
} catch (Exception e) {
e.printStackTrace();
throw new ExamException("保存判断题出现异常!");
}
}
public void saveOrUpdateSelectOne(SelectOne selectOne) throws ExamException{
ExamDao dao = (ExamDaoImpl) BeanFactory.getBean("examDao");
try {
dao.saveOrUpdateSelectOne(selectOne);
} catch (Exception e) {
e.printStackTrace();
throw new ExamException(e.getMessage());
}
}
public void saveOrUpdateStudent(Student student) throws ExamException {
ExamDao dao = (ExamDaoImpl) BeanFactory.getBean("examDao");
try {
dao.saveOrUpdateStudent(student);
} catch (Exception e) {
e.printStackTrace();
throw new ExamException(e.getMessage());
}
}
public List<Student> listStudents() throws ExamException {
ExamDao dao = (ExamDaoImpl) BeanFactory.getBean("examDao");
try {
return dao.listStudents();
} catch (Exception e) {
e.printStackTrace();
throw new ExamException(e.getMessage());
}
}
public Student getStudentByXuehao(String xuehao) throws ExamException {
ExamDao dao = (ExamDaoImpl) BeanFactory.getBean("examDao");
try {
return dao.getStudentByXuehao(xuehao);
} catch (Exception e) {
e.printStackTrace();
throw new ExamException(e.getMessage());
}
}
public Subject getSubjectByName(String name) throws ExamException {
ExamDao dao = (ExamDaoImpl) BeanFactory.getBean("examDao");
try {
return dao.getSubjectByName(name);
} catch (Exception e) {
e.printStackTrace();
throw new ExamException("保存选择题时出现异常!");
}
}
public void saveOrUpdateSubject(Subject subject) throws ExamException {
ExamDao dao = (ExamDaoImpl) BeanFactory.getBean("examDao");
try {
dao.saveOrUpdateSubject(subject);
} catch (Exception e) {
e.printStackTrace();
throw new ExamException("保存科目信息时抛出异常!");
}
}
public void changeState() throws ExamException {
ExamDao dao = (ExamDaoImpl) BeanFactory.getBean("examDao");
try {
dao.changeState();
} catch (Exception e) {
e.printStackTrace();
throw new ExamException("改变考试科目状态抛出异常!");
}
}
public int getChoiceNum(Subject subject) throws ExamException {
ExamDao dao = (ExamDaoImpl) BeanFactory.getBean("examDao");
try {
System.out.println("得到选题 : "+subject.getName());
return dao.getChoiceOneNum(subject);
} catch (Exception e) {
e.printStackTrace();
throw new ExamException("得到选择题的数目发现异常!");
}
}
public int getSelectOneNum(Subject subject) throws ExamException {
ExamDao dao = (ExamDaoImpl) BeanFactory.getBean("examDao");
try {
return dao.getSelectOneNum(subject);
} catch (Exception e) {
e.printStackTrace();
throw new ExamException("得到判断题的数目发现异常!");
}
}
public CChoice getChoice(int num) throws ExamException {
ExamDao dao = (ExamDaoImpl) BeanFactory.getBean("examDao");
try {
CChoice choice = dao.getChoice(num);
return choice;
} catch (Exception e) {
e.printStackTrace();
throw new ExamException(e.getMessage());
}
}
public SelectOne getSelectOne(int num) throws ExamException {
ExamDao dao = (ExamDaoImpl) BeanFactory.getBean("examDao");
try {
SelectOne selectOne = dao.getSelectOne(num);
return selectOne;
} catch (Exception e) {
e.printStackTrace();
throw new ExamException(e.getMessage());
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -