citydaoimpl.java

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

JAVA
45
字号
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.CityDao;
import com.sunny.test.model.City;

public class CityDaoImpl extends HibernateDaoSupport implements CityDao
{
	

	public void save(City city) throws Exception
	{
		getHibernateTemplate().saveOrUpdate(city);
	}
	
	public void delete(int id) throws Exception
	{
		getHibernateTemplate().delete(getCity(id));
		
	}	
	public City getCity(int id) throws Exception
	{
		return (City)getHibernateTemplate().get(com.sunny.test.model.City.class, id);
	}
	public List getCitys() throws Exception
	{
		String hql = "from City c,Province p where c.provinceId=p.id order by c.provinceId";
		List list = getHibernateTemplate().find(hql);
		return list;
	}

	public List queryCityById(int provinceId) throws Exception
	{
		String hql = "from City c where c.provinceId=? order by c.provinceId";
		Query q = super.getSession().createQuery(hql);
		q.setInteger(0, provinceId);
		List list = q.list();	
		return list;
	}	

}

⌨️ 快捷键说明

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