⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 papertypedaoimp.java

📁 该在线考试关系统(B/S结构)主要采用JAVA语言开发涉及主要WEB技术有:Struts+Spring+Hibernate框架
💻 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 + -