📄 exampaperdaoimp.java
字号:
package dao.hibernate;
import java.util.Collection;
import java.util.List;
import org.hibernate.Query;
import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.springframework.orm.hibernate3.HibernateTemplate;
import po.Oexampaper;
import po.Ostudent;
import dao.IExamPaperDao;
public class ExamPaperDaoImp implements IExamPaperDao
{
private SessionFactory sf;
private HibernateTemplate template;
public SessionFactory getSf()
{
return sf;
}
public void setSf(SessionFactory sf)
{
this.sf = sf;
//通过session工厂得到hibernate模版
template = new HibernateTemplate(sf);
}
public void addExamPaper(Oexampaper exam)
{
exam.setStatus("关闭考试");
template.save(exam);
sf.close();
}
public void delExamPaper(String id)
{
template.delete(this.findExamPaperByid(id));
sf.close();
}
public List findAllExamPaper()
{
List list = template.find("from Oexampaper");
sf.close();
return list;
}
public Oexampaper findExamPaperByid(String id)
{
Oexampaper exam = (Oexampaper) template.get(Oexampaper.class, Long.parseLong(id));
return exam;
}
public void updataExamPaper(Oexampaper exam)
{
template.saveOrUpdate(exam);
sf.close();
}
public Collection findByExamkey(int currow, int pagesize, String text)
{
Collection TestList = null;
Query q = null;
SessionFactory sf = template.getSessionFactory();
Session s = sf.openSession();
String hql = "";
//没有条件
if (null == text)
{
hql = "from Oexampaper o order by o.id asc";
q = s.createQuery(hql);
}
//1个条件
if(null != text)
{
hql = "from Oexampaper o where o.name like :name";
q = s.createQuery(hql);
q.setString("name", "%" + text + "%");
}
q.setFirstResult(currow);
q.setMaxResults(pagesize);
TestList = q.list();
s.close();
return TestList;
}
public void changeStatus(String id)
{
Oexampaper exam = this.findExamPaperByid(id);
if("关闭考试".equals(exam.getStatus()))
{
exam.setStatus("开放考试");
template.saveOrUpdate(exam);
}
else
{
exam.setStatus("关闭考试");
template.saveOrUpdate(exam);
}
sf.close();
}
public int changePoint(String answer, String answers, int point)
{
if(null!=answer && answer.equals(answers))
{
return point;
}
else
{
return 0;
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -