📄 citydaoimpl.java
字号:
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 + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -