📄 papertypedaoimp.java
字号:
package dao.hibernate;
import java.util.List;
import org.hibernate.Query;
import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.springframework.orm.hibernate3.HibernateTemplate;
import po.Opapertype;
import dao.IPaperTypeDao;
public class PaperTypeDaoImp implements IPaperTypeDao
{
private SessionFactory sf;
private HibernateTemplate template;
public SessionFactory getSf()
{
return sf;
}
public void setSf(SessionFactory sf)
{
this.sf = sf;
template = new HibernateTemplate(sf);
}
public void addPaperType(Opapertype ptype)
{
template.save(ptype);
sf.close();
}
public void delPaperType(long id)
{
template.delete(this.findPaperType(id));
sf.close();
}
public List findAllPaperType()
{
List list = template.find("from Opapertype");
sf.close();
return list;
}
public void updataPaperType(Opapertype ptype)
{
template.saveOrUpdate(ptype);
sf.close();
}
public Opapertype findPaperType(long id)
{
Opapertype ptype = (Opapertype) template.get(Opapertype.class, id);
sf.close();
return ptype;
}
public boolean judgeTypeContain(String name)
{
SessionFactory sf = template.getSessionFactory();
Session s = sf.openSession();
String hql = "from Opapertype as o WHERE o.name=?" ;
Query q = s.createQuery(hql);
q.setString(0,name);
List list = q.list();
sf.close();
if(list.size()==0)
{
return true;
}
else
{
return false;
}
/* String hql = "select o from Opapertype o where o.name = '"+name+"'";
System.out.print(hql);
// String sql = "select * from Opapertype where name = '"+name+"'";
List list = template.find(hql);*/
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -