删除
public void deleteFixedAsset(FixedAssetForm fixedAssetForm)throws Exception{
getHibernateTemplate().delete(fixedAssetForm);
}
添加
public void addFixedAsset(FixedAssetForm fixedAssetForm) throws Exception{
getHibernateTemplate().save(fixedAssetForm);
}
修改
public void updateFixedAsset(FixedAssetForm fixedAssetForm)throws Exception{
getHibernateTemplate().saveOrUpdate(fixedAssetForm);
}
查询
public List<FixedAssetForm> getFixedAssetS(long fixedAssetCode) throws Exception{
String hql = "from FixedAssetForm FIXEDASSET where FIXEDASSET.fixedAssetCode="+fixedAssetCode+" order by FIXEDASSET.fixedAssetCode";
List<FixedAssetForm> list = getHibernateTemplate().find(hql);
return list;
}
我的源代码,不知道你能看懂不
public void deleteFixedAsset(FixedAssetForm fixedAssetForm)throws Exception{
getHibernateTemplate().delete(fixedAssetForm);
}
添加
public void addFixedAsset(FixedAssetForm fixedAssetForm) throws Exception{
getHibernateTemplate().save(fixedAssetForm);
}
修改
public void updateFixedAsset(FixedAssetForm fixedAssetForm)throws Exception{
getHibernateTemplate().saveOrUpdate(fixedAssetForm);
}
查询
public List<FixedAssetForm> getFixedAssetS(long fixedAssetCode) throws Exception{
String hql = "from FixedAssetForm FIXEDASSET where FIXEDASSET.fixedAssetCode="+fixedAssetCode+" order by FIXEDASSET.fixedAssetCode";
List<FixedAssetForm> list = getHibernateTemplate().find(hql);
return list;
}
我的源代码,不知道你能看懂不
上面加载hibernate包的时候会给你提示是否选择这样的例子的
[email protected]
public class HibernateEmployDAO extends GenericDao<Employ, String> implements EmployDAO {
public Employ[] findByPlan(String planId) {
String hql = "FROM Employ lt WHERE lt.employ.id = ?";
List<Employ> list = find(hql, planId);
return GenericsUtils.toArray(list);
}
}
即可调用二楼提供的方法啦
首先获得hibernateTemplate()即this.getHibernateTemplate()再调用下面的方法
● void delete(Object entity),删除指定持久化实例。 ● deleteAll(Collection entities),删除集合内全部持久化类实例。 ● find(String queryString),根据HQL查询字符串来返回实例集合。 ● findByNamedQuery(String queryName),根据命名查询返回实例集合。 ● get(Class entityClass, Serializable id),根据主键加载特定持久化类的实例。 ● save(Object entity),保存新的实例。 ● saveOrUpdate(Object entity),根据实例状态,选择保存或者更新。 ● update(Object entity),更新实例的状态,要求entity是持久状态。