?? 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 + -