provincedaoimpl.java

来自「该项目基于mvc模式」· Java 代码 · 共 58 行

JAVA
58
字号
package com.sunny.test.dao.impl;

import java.util.List;
import org.hibernate.Query;
import org.springframework.orm.hibernate3.support.HibernateDaoSupport;
import com.sunny.test.dao.ProvinceDao;
import com.sunny.test.model.Province;

public class ProvinceDaoImpl extends HibernateDaoSupport implements ProvinceDao
{

	public List findAll(int start,int offset) throws Exception
	{
		List all = null;
		String hql = "from Province order by name";
		Query q = this.getSession().createQuery(hql);
		q.setFirstResult(start);
		q.setMaxResults(offset);
		all = q.list();
		return all;
	}

	public int getAllCounts() throws Exception
	{
		int count=0;
		String hql = "from Province";
		Query q = super.getSession().createQuery(hql);
		List list = q.list();
		count = list.size();
		return count;
	}

	public void save(Province province) throws Exception
	{
		getHibernateTemplate().saveOrUpdate(province);
	}
	
	public void delete(int id) throws Exception
	{
		
		getHibernateTemplate().delete(getProvince(id));
		
		
		
	}	
	public Province getProvince(int id) throws Exception
	{
		return (Province)getHibernateTemplate().get(com.sunny.test.model.Province.class, id);
	}
	public List getProvinces() throws Exception
	{
		String hql = "from Province order by name";
		List list = getHibernateTemplate().find(hql);
		return list;
	}	

}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?